struct HASH_CMP {
bool operator()(vector<int> V, vector<int> W) const {
for(int i = 0; i < 10; i++)
if(V[i] != W[i]) return false;
return true;
}
};
hash_map< std::vector<int>, int, HASH_CMP > H;
long long inHash(const vector<int> &V) {
if(H.find(V) == H.end()) return -1; //this line
return H[V];
}
我已经宣布了下述散,给上述比较级和我收到该行错误提到说:的hash_map < vector<int>,使用int>的错误,当查找功能
敌不过调用'
(const HASH_CMP) (const std::vector<int, std::allocator<int> >&)
我需要一些帮助来解决这段代码。
你从来没有写过[哈希函数](http://www.sgi.com/tech/stl/HashFunction.html)(返回一个'size_t')。如果您有办法对其进行哈希处理,您只能将其放在哈希映射中。 – 2013-03-19 10:20:04
我相信你希望通过引用'operator()'中的'const'来接受你的向量。' – 2013-03-19 10:20:08
顺便说一句,对于'std :: vector',有一个相等比较运算符=='。它与你的完全不一样,但它可能是有用的。 – juanchopanza 2013-03-19 10:55:55