Problem with std::tr1::hash
Code:
#include <tr1/unordered_map>
class sample {
public:
sample(int number) : _number(number) {}
bool operator<(const sample& rhs) const { return _number < rhs._number; }
bool operator==(const sample& rhs) const { return _number == rhs.=
_number; }
size_t hash() const { return _number; }
private:
// Prevent object copy
sample(const sample&);
sample& operator=(const sample&);
private:
int _number;
};
int main()
{
std::tr1::unordered_map<sample&, sample&> s2s;
sample s1(10);
sample s2(10);
s2s.insert(std::pair<sample&, sample&>(s1, s2));
return 0;
}
Compile error:
/tmp/ccqXe5A7.o: In function `std::tr1::__detail::_Hash_code_base<sample&, =
std::pair<sample&, sample&>, std::_Select1st<std::pair<sample&, sample&> >,=
std::equal_to<sample&>, std::tr1::hash<sample&>, std::tr1::__detail::_Mod_=
range_hashing, std::tr1::__detail::_Default_ranged_hash, false>::_M_hash_co=
de(sample&) const':
specialization.cc:(.text._ZNKSt3tr18__detail15_Hash_code_baseIR6sampleSt4pa=
irIS3_S3_ESt10_Select1stIS5_ESt8equal_toIS3_ENS_4hashIS3_EENS0_18_Mod_range=
_hashingENS0_20_Default_ranged_hashELb0EE12_M_hash_codeES3_[std::tr1::__det=
ail::_Hash_code_base<sample&, std::pair<sample&, sample&>, std::_Select1st<=
std::pair<sample&, sample&> >, std::equal_to<sample&>, std::tr1::hash<sampl=
e&>, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_r=
anged_hash, false>::_M_hash_code(sample&) const]+0x23): undefined reference=
to `std::tr1::hash<sample&>::operator()(sample&) const'
Could anyone please tell me how the operator() of std::tr1::hash is defined=
? Or why am I getting this error?
I remember using a version of hash (which comes with hash_set/hash_map) tha=
t calls hash() function of argument.
Thanks.