C++ - calling a method from a class template -
i'm having problem class template in c++. i'm making hash table.
i'm using functor class template specify hash function each instance of table.
ie: 1 table has integers keys, strings values. have strings keys , integers values, etc...
class hashstring { public: unsigned long operator()(std::string& key, const unsigned int tablesize) { // ..... } }; template<typename keytype, typename valuetype, class hashfunctor> class hashtable { public: // .... private: hashfunctor myhash; };
and let's want call method called "myhash" hash key, @ first call doing:
myhash(key, table.size())
but gcc doesn't find function overload hashfuntor(string, unsigned int) example.
could tell me how call myhash? (note: not change structure of functors)
edit: error message actual solution
instantiated ‘void tp3::table<typeclef, typedonnee, fonchachage>::insert(const typeclef&, const typedonnee&) [with typeclef = int, typedonnee = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, fonchachage = tp3::hachestring]’ no match call ‘(tp3::hachestring) (tp3::table<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, tp3::hachestring>::hashentry&)’
edit: everywhere says hachestring in fact hashstring (i've translated code paste here).
operator() in hashstring private , not const-correct. should const member function taking const std::string& first parameter. second parameter not need const.
you seem calling hashentry second parameter. hashentry? takes unsigned int!
that might solve of problems.
i assume hachestring / hashstring difference typo.
Comments
Post a Comment