unordered_map Help

Hi,

I wrote this:

1
2
3
4
5
6
7
8
9
10
11
struct eqstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) == 0;
  }
};

  unordered_map<const char*, class c_simbolo *, hash<const char*>, eqstr> tabla;  
  unordered_map<const char*, c_simbolo *, hash<const char*>, eqstr> ::iterator it;  
 unordered_map<const char*, c_simbolo *, hash<const char*>, eqstr> ::iterator it_busquedas; 


But when I try to search wtih this:

1
2
3
4
5
6
7
8
9
c_simbolo *c_tabla_simbolos :: buscar (char *ident)
{
  it_busquedas=tabla.find (ident);

  if (it_busquedas == tabla.end())
    return NULL;	
  else{
    return (*it_busquedas).second;}
}


The function doesn't work. Never find the ident.

If someone could help me I would really apreciate.
hash<const char*> is a hash of the value of a pointer, not a hash of the value of some null-terminated array that pointer might be pointing to. Use std::string as the key.
Last edited on
Thank you so much.

You really helpel me
Topic archived. No new replies allowed.