| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Amit Bhatia" |
| Date: |
22 Sep 2007 10:19:00 AM |
| Object: |
Insert function in hash_map. |
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 `
__gnu_cxx::hash_map<std::pair<int, int>, Qd_Node,Qd_Node_Hasher,
std::equal_to<std::pair<int, int> >, std::allocator<Qd_Node>
::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.
.
|
|
| User: "James Kanze" |
|
| Title: Re: Insert function in hash_map. |
23 Sep 2007 12:37:25 PM |
|
|
On Sep 22, 5:19 pm, Amit Bhatia <abha...@nospam.nospam.com> wrote:
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
pair< pair< int, int > const, Qd_Node >. The name of the hasher
certainly suggests that the first condition is not met.
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 ) ) ;
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
|
|
|
|

|
Related Articles |
|
|