Insert function in hash_map.

A

Amit Bhatia

Hi,
I have defined something like the following in tree.h file:

//everything else including using namespace __gnu_cxx;
typedef hash_map<pair<int,int>, Qd_Node, Qd_Node_Hasher> Loc_Tree;
vector<Loc_Tree> tree;
//more stuff;

Now when I try do something like this in tree.C file:
#include "tree.h"
//
Qd_Node node(//constructor);
tree[0].insert(node);

the compiler complains with the following message:

error: no matching function for call to `
Qd_Node said:
>::insert(Qd_Node&)'
/usr/include/gcc/darwin/3.3/c++/ext/hash_map:181: error: candidates are:
std::pair<typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>,
_Key,
_HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey,
_Alloc>::iterator, bool> __gnu_cxx::hash_map<_Key, _Tp, _HashFcn,
_EqualKey,
_Alloc>::insert(typename __gnu_cxx::hashtable<std::pair<const _Key,
_Tp>,
_Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey,
_Alloc>::value_type&) [with _Key = std::pair<int, int>, _Tp =Qd_Node,
_HashFcn =Qd_Node_Hasher, _EqualKey = std::equal_to<std::pair<int,
int> >, _Alloc = std::allocator<Qd_Node>]

From what I read on the SGI website, this looks correct to me. I am
trying to insert an object in the hash_map, using defined function.

Why is the compiler complaining?


thanks,
-a.
 
J

James Kanze

I have defined something like the following in tree.h file:
//everything else including using namespace __gnu_cxx;
typedef hash_map<pair<int,int>, Qd_Node, Qd_Node_Hasher> Loc_Tree;

So pair< int, int > is the key type, and Qd_Node the keyed type.
This means that 1) the hasher should calculate a hash conde on
pair< int, int >, and 2) the value type of the table is
vector<Loc_Tree> tree;
//more stuff;
Now when I try do something like this in tree.C file:
#include "tree.h"
//
Qd_Node node(//constructor);
tree[0].insert(node);

And here, you're trying to insert a Qd_Node, rather than a
pair< pair< int, int >, Qd_Node >.

In such cases, I usually would use something like:

tree[ 0 ].insert(
Loc_Tree::value_type( pair< int, int >( i, j ), node ) ) ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top