哈希表上没有匹配函数
No matching function on hashtable
当我尝试从以下代码行调用创建哈希函数时,我收到错误 没有匹配函数
myHash.create("5", "Data");
checkTest("testSimpleIntHash #1", "Data", myHash.retrieve("5"));
这个想法是,create 从 KeyValuePair 类接收密钥,然后该方法将对密钥进行哈希处理,转到该存储桶,然后插入键值对。我相信我收到此错误,因为我没有输出到字符串。但是,我无法弄清楚使用 create 方法将键值对正确输出为字符串的语法。(我正在使用std::list
,并且我的KeyValuePair
类运行正常(
template<typename T> class HashTable
{
public:
static const unsigned int NUM_BUCKETS = 100000;
HashTable create(const string& key, const T& item)
{
int temp = hash(key);
arr[NUM_BUCKETS].push_back(KeyValuePair<T>(temp, item));
}
private:
int hash(const string& key) const;
//Make an array of linked lists of KeyValuePair objects.
list<KeyValuePair<T>> arr[NUM_BUCKETS];
};
template <typename T>
int HashTable<T>::hash(const string& key) const {
int temp = 0;
for (int i = key.length(); i >= 0; i--) {
temp = (13 * temp + key[i]) % NUM_BUCKETS;
}
return temp;
}
在 create
方法中,可以返回对类本身的引用。
HashTable& create(const string& key, const T& item)
{
int temp = hash(key);
arr[NUM_BUCKETS].push_back(KeyValuePair<T>(temp, item));
return *this;
}
但无论如何,你没有签署它。
并且您需要在类HashTable
中声明retrieve
方法:例如:
string retrieve(const string& input)
{
string result;
//Not sure wath do you pretend to be this method.
//But it will transform your input in your result
return result;
}
相关文章:
- 在 C++ 中为特定哈希表创建插入函数
- 哈希表添加函数
- 具有完美哈希函数的哈希表比数组好吗?
- 删除为应该在哈希表中的记录返回 false 的函数
- 在哈希表复制构造函数中找不到错误
- 哈希表上没有匹配函数
- C++ - 带有函数指针的哈希表
- 哈希表,其中键是字符串,值是 c++ 中的函数
- 将函数名称和属性存储在哈希表中
- 如何实现哈希表的擦除函数
- C++:为unordered_set编写一个自定义哈希函数,该函数使用哈希表中的桶数
- 使用链接的哈希表析构函数
- 如何在 c++ 中编写正确的哈希表析构函数
- 复制哈希表的构造函数
- 哈希表-哈希函数的实现
- 使用哈希表中的派生类搜索函数
- 哈希表单独链接中没有用于调用xxx的匹配函数
- 在不使用预定义的C++函数的情况下,按字母顺序打印存储在哈希表中每个索引处的名称
- 哈希表中搜索函数的平均复杂度
- 实现哈希表,插入函数导致"scope"错误