Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
STL hash_set problem, SGI impl
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Timo Qvist, post: 1520051"] Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and I've having problem instantiating a hash_set with a custom hash function, I could really use some help sifting through g++ (v3.3.3) error message on this particular problem. I want a hash_set with class pointers as the hashed type, my class is simply called Transition, the following code doesn't work; using namespace __gnu_cxx; typedef struct _HashFunc : public unary_function<Transition *, size_t > { size_t operator()( const Transition *t ) const { return t->getID(); } } HashFunc; void foo( Transition *trans ) { hash_set< Transition *, hash<HashFunc> > my_hashset; // This far the compiler doesn't complain... myhashset.insert( trans ); // however, adding this instatiation causes the following error; } /usr/include/c++/3.3.3/ext/stl_hashtable.h: In member function `size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num_key(const _Key&, unsigned int) const [with _Val = Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey = std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]': /usr/include/c++/3.3.3/ext/stl_hashtable.h:519: instantiated from `size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val = Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey = std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]' /usr/include/c++/3.3.3/ext/stl_hashtable.h:884: instantiated from `void __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::resize(unsigned int) [with _Val = Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey = std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]' /usr/include/c++/3.3.3/ext/stl_hashtable.h:378: instantiated from `std::pair<__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val = Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey = std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]' /usr/include/c++/3.3.3/ext/hash_set:175: instantiated from `std::pair<typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Key>, _EqualKey, _Alloc>::const_iterator, bool> __gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>::insert(typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Key>, _EqualKey, _Alloc>::value_type&) [with _Value = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>, _EqualKey = std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]' net.cpp:328: instantiated from here /usr/include/c++/3.3.3/ext/stl_hashtable.h:514: error: no match for call to `( const __gnu_cxx::hash<HashFunc>) (Transition* const&)' Ok, so I've figured out that somewhere deep down in the template we try and call the HashFunc operator() and we cant find a match, I just cant fix the HashFunc functor with the correct types for this to work? Or am I missing something? /tq [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
STL hash_set problem, SGI impl
Top