我正在使用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