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 the in addItem() function when I try to Table.emplace().
Error for code as shown above: C2661: 'std::pair<const _Kty,_Ty>::pair': no overloaded function takes 2 arguments in file xmemory
Error for when using table.insert(): C2664: 'std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>> std::_Hash<std::_Umap_traits<_Kty,std::unique_ptr<T,std::default_delete<Object>>,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert(std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,const std::pair<const _Kty,std::unique_ptr<T,std::default_delete<Object>>> &)': cannot convert argument 1 from 'int' to 'std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>' in file HashTable.h
Error for when using table.insert or table.emplace(std::make_pair(tailPointer, itemPtr)): C2440: '<function-style-cast>': cannot convert from 'initializer list' to '_MyPair' in file utility
Aucun commentaire:
Enregistrer un commentaire