help-gplusplus
[Top][All Lists]
Advanced

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

Re: how to use hash_map with std::string as key type?


From: dbtouch
Subject: Re: how to use hash_map with std::string as key type?
Date: Fri, 23 Jan 2009 20:04:58 -0800 (PST)
User-agent: G2/1.0

On Jan 23, 10:55 pm, dbtouch <dbto...@gmail.com> wrote:
> Dear G++ Users,
>
> I am using g++ (gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)) and I
> cannot use hash_map with std::string as key type. Here is the test
> program I have:
>
> #include <string>
> #include <ext/hash_map>
> using namespace __gnu_cxx;
>
> typedef hash_map<std::string, int> MyHashTyp;
>
> int main() {
>         MyHashTyp map;
>         MyHashTyp::iterator itr;
>
>         itr=map.find(std::string("hello"));
>         return 1;
>
> }
>
> The compiler reported error as:
>
> strhashmap.cpp:11:   instantiated from here
> /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/
> ext/hashtable.h:596: error: no match for call to â(const
> __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > >) (const std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >&)â
> make: *** [strhashmap.o] Error 1
>
> When I change key type to char, it compiles. Can you help me on this?
>
> Thanks and Happy Chinese New Year!
>
> dbtouch

I got the answer from the group. Thanks, Ben.



reply via email to

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