help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Some strange behaviors of hash_map


From: 杨 波
Subject: Some strange behaviors of hash_map
Date: Fri, 15 May 2009 19:06:29 -0700 (PDT)
User-agent: G2/1.0

Hi,
   I am trying to use the ext/hash_map of gnu C++, but I observe some
strange behaviors, please help me, my code is :

#include <iostream>
#include <cstring>
#include <ext/hash_map>

using namespace std;
using namespace __gnu_cxx;

class SE {
public:
        bool operator ()(const char *a, const char *b);
};
bool SE::operator ()(const char *a, const char *b)
{
        return strcmp(a, b);
}

int main(int argc, char **argv)
{
        hash_map<const char *, int, hash<const char *>, SE> map;
        map["abc"] = 1;
        map["ab"] = 10;

        cout << map["abc"] << endl << map["ab"] << endl << map["d"] <<
endl;;

        return 0;
}


------------------------
But to my surprise, all the three map["..."] output is '0', I am
wondering, is there any place I am writing wrong code?

Thanks!

Regards!
Bo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]