如何在无序映射中为自定义类重用字符串类的哈希函数
How to reuse hashing function of string class for custom class in unordered map?
我正在C++中定义一个无序映射,如下所示:
unordered_map<CustomClass, int, CustomClassHash, CustomClassEq> myMap;
假设我已经能够成功地定义CustomClassEq。我希望CustomClass的散列,即CustomClassHash委托给类内字符串属性的散列。有没有一种方法可以在CustomClassHash的定义中重用字符串类的哈希函数?
这就是我想做的:
struct CustomClassHash {
long operator()(const CustomClass &c) const {
string s = c.getString();
// TODO: return the hash of s
}
};
您可以使用:
return hash<string>()(c.get_name());
查看后的第二条评论
对象作为无序映射的密钥
相关文章:
- 字符串函数在目标C++上运行时C++返回空
- 字符串函数返回奇怪的值
- 这里的字符串函数是什么意思
- 在字符串函数中抛出'char const*'实例后调用的终止
- 为什么 stl 字符串C++函数有时出错有时会出错?
- 从C++为字符串函数设置_ENV
- 来自 2D 数组的字符串函数
- 返回最长的公共子字符串函数 c ++
- 使用getline和字符串函数C++程序中的分段错误
- 在字符串函数的指针中返回地址
- 字符串函数:strcat()
- 这个子字符串函数有什么问题
- 字符串函数不返回字符串? C++
- 使用向量和字符串函数返回字符串
- 尝试修复一个字符串函数,该函数采用字符串并通过替换一些单词来更改它
- 逐字读取字符数组,无需字符串函数
- 我从我的字符串函数返回到主函数
- 为什么我不能从字符串函数返回字符串数组?
- 如何在不使用字符串函数的情况下在char数组中找到字符串?(C )
- 带有 #include< iostream.h> 的程序允许使用 strlen() 等字符串函数。为什么?