I'm trying to create a class for a hash table to contain unique pointers, but whenever I try to add a pointer to the table I get an error which points to a different file from a library I am using.
I've tried using .insert()
instead of .emplace()
. I've tried passing in a pair of the key and the pointer.
Both of these have resulted in a different error to the original
here is the Hash_Table class:
///<summary>
/// A struct for a hash table
///</summary>
template <typename T>
struct Hash_Table
{
public:
///<summary>
/// Add an item to the hash table & return the item key
///</summary>
int addItem(T newItem) {
// Make the item into a unique pointer
std::unique_ptr<T> itemPtr = std::make_unique<T>(newItem);
//std::pair<int, std::unique_ptr<T>> pair = std::make_pair(tailPointer, itemPtr);
while (!Table.emplace(tailPointer, itemPtr).second) {
tailPointer++;
//pair.first++;
}
tailPointer++;
return tailPointer--;
};
private:
///<summary>
/// The actual hash table
///</summary>
std::unordered_map<int, std::unique_ptr<T>> Table;
///<summary>
/// Points to the key of the last item added to the hash table
///</summary>
int tailPointer;
};
The issue happens in addItem()
function when I try to table.emplace()
.
Error in file xmemory for code as shown above:
C2661: 'std::pair::pair': no overloaded function takes 2 arguments
Error in file HashTable.h for when using table.insert()
:
C2664: 'std::_List_iterator>> std::_Hash>,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert(std::_List_const_iterator>>,const std::pair>> &)': cannot convert argument 1 from 'int' to 'std::_List_const_iterator>>'
Error in file utility for when using table.insert
or table.emplace(std::make_pair(tailPointer, itemPtr))
:
C2440: '': cannot convert from 'initializer list' to '_MyPair'