我正在使用C++中的散列表。散列函数:reinterpret_cast <unsigned long>无效的投射
// Default hash function class
template <typename K>
struct KeyHash {
unsigned long operator()(const K& key) const {
return reinterpret_cast<unsigned long>(key) % TABLE_SIZE;
}
};
后来,当我宣布哈希表:
HashTable<int, std::string> hmap;
其显示:
从 '廉政' 类型 'unsigned_long_int'
无效的转换
这里有什么问题reinterpret_cast<unsigned long>
?
也许是'sizeof(unsigned long)!= sizeof(int)',所以“重新解释位模式”可能没有意义......我不确定。 – 2014-08-30 19:25:42
这个****是谁给的那个downvote?所以每个人都不会像你一样了解所有事情。 – 2014-08-30 19:27:55
看来你是在假设我给了你那个downvote。我没有。 [证明](http://imgur.com/2tey48m)。 – 2014-08-30 19:29:39