27 Aug
2010
27 Aug
'10
5:53 p.m.
Dear all, Should not the program in the P.S. output "I got used!"? If not, how can I ensure that it's size_t hash_value(B*) which gets called upon use of bPtrHasher's operator()? TIA, --Hossein P.S. namespace Bs { struct B { virtual string id() const {return "This is a B!";} }; struct D: B { string id() const {return "And, this one is a D.";} }; size_t hash_value(B* bptr) { cout << "I got used!" << endl; boost::hash<string> hasher; return hasher(bptr->id()); } } int main() { Bs::B* bp1 = new Bs::B; Bs::B* bp2 = new Bs::D; boost::hashBs::B* bPtrHasher; size_t h1 = bPtrHasher(bp1), h2 = bPtrHasher(bp2); }