Why won't this hash_map compile?

Discussion in 'C++' started by Mark, Dec 15, 2003.

  1. Mark

    Mark Guest

    Hi,

    I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It
    will compile if I use <map> but I get a bunch of template compile errors
    when I change it to hash_map. Any suggestions? My program and the errors
    are below...

    #include <ext/hash_map>
    #include <string>

    using namespace std;

    __gnu_cxx::hash_map<string, int> storage;

    int main()
    {
    pair<string, int> item("blah", 1);
    storage.insert(item);
    }

    When compiled I get the following:
    g++ hm.cpp -o hm
    /usr/include/c++/3.2.2/ext/stl_hashtable.h: In member function `size_t
    __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
    _Alloc>::_M_bkt_num_key(const _Key&, unsigned int) const [with _Val =
    std::pair<const std::string, int>, _Key = std::string, _HashFcn =
    __gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std::pair<const
    std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
    std::allocator<int>]':
    /usr/include/c++/3.2.2/ext/stl_hashtable.h:522: instantiated from `size_t
    __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
    _Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val =
    std::pair<const std::string, int>, _Key = std::string, _HashFcn =
    __gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std::pair<const
    std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
    std::allocator<int>]'
    /usr/include/c++/3.2.2/ext/stl_hashtable.h:887: instantiated from `void
    __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
    _Alloc>::resize(unsigned int) [with _Val = std::pair<const std::string,
    int>, _Key = std::string, _HashFcn = __gnu_cxx::hash<std::string>,
    _ExtractKey = std::_Select1st<std::pair<const std::string, int> >, _EqualKey
    = std::equal_to<std::string>, _Alloc = std::allocator<int>]'
    /usr/include/c++/3.2.2/ext/stl_hashtable.h:381: instantiated from
    `std::pair<__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey,
    _EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn,
    _ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val =
    std::pair<const std::string, int>, _Key = std::string, _HashFcn =
    __gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std::pair<const
    std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
    std::allocator<int>]'
    /usr/include/c++/3.2.2/ext/hash_map:171: instantiated from
    `std::pair<__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(__gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key,
    _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey,
    _Alloc>::value_type&) [with _Key = std::string, _Tp = int, _HashFcn =
    __gnu_cxx::hash<std::string>, _EqualKey = std::equal_to<std::string>, _Alloc
    = std::allocator<int>]'
    hm.cpp:14: instantiated from here
    /usr/include/c++/3.2.2/ext/stl_hashtable.h:517: no match for call to `(const
    __gnu_cxx::hash<std::string>) (const std::basic_string<char,
    std::char_traits<char>, std::allocator<char> >&)'
    make: *** [hm] Error 1
    Mark, Dec 15, 2003
    #1
    1. Advertising

  2. "Mark" <> wrote...
    > I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It
    > will compile if I use <map> but I get a bunch of template compile errors
    > when I change it to hash_map. Any suggestions?[...]


    hash_map is not a standard class or template, so it's OT here unless
    you provide its full definition.

    If 'hash_map' is part of gcc, I recommend gnu.g++.help newsgroup.

    Victor
    Victor Bazarov, Dec 15, 2003
    #2
    1. Advertising

  3. Mark wrote:
    > Hi,
    >
    > I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It
    > will compile if I use <map> but I get a bunch of template compile errors
    > when I change it to hash_map. Any suggestions? My program and the errors
    > are below...
    >
    > #include <ext/hash_map>
    > #include <string>
    >
    > using namespace std;
    >
    > __gnu_cxx::hash_map<string, int> storage;
    >
    > int main()
    > {
    > pair<string, int> item("blah", 1);
    > storage.insert(item);
    > }
    >
    > When compiled I get the following:
    > g++ hm.cpp -o hm

    [...]
    Have a look here:
    http://gcc.gnu.org/ml/libstdc /2002-04/msg00107.html

    Mike
    Michael Mellor, Dec 15, 2003
    #3
  4. Mark

    Mark Guest

    Perfect! Thanks Michael!

    Although I may end up just using <map> since my data is small and it'd be
    nice to conform to the standard (although apparently hash_map is being added
    to the standard on the next go-around).

    Mark


    "Michael Mellor" <> wrote in message
    news:brlglc$sa6$...
    > Mark wrote:
    > > Hi,
    > >
    > > I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key.

    It
    > > will compile if I use <map> but I get a bunch of template compile errors
    > > when I change it to hash_map. Any suggestions? My program and the

    errors
    > > are below...
    > >
    > > #include <ext/hash_map>
    > > #include <string>
    > >
    > > using namespace std;
    > >
    > > __gnu_cxx::hash_map<string, int> storage;
    > >
    > > int main()
    > > {
    > > pair<string, int> item("blah", 1);
    > > storage.insert(item);
    > > }
    > >
    > > When compiled I get the following:
    > > g++ hm.cpp -o hm

    > [...]
    > Have a look here:
    > http://gcc.gnu.org/ml/libstdc /2002-04/msg00107.html
    >
    > Mike
    Mark, Dec 15, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AdamB
    Replies:
    5
    Views:
    596
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    878
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,833
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    9
    Views:
    520
    P.J. Plauger
    May 10, 2006
  5. Nagaraj
    Replies:
    1
    Views:
    854
    Lionel B
    Mar 1, 2007
Loading...

Share This Page