473,883 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why won't this hash_map compile?

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::hash table<_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<cons t
std::string, int> >, _EqualKey = std::equal_to<s td::string>, _Alloc =
std::allocator< int>]':
/usr/include/c++/3.2.2/ext/stl_hashtable.h :522: instantiated from `size_t
__gnu_cxx::hash table<_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<cons t
std::string, int> >, _EqualKey = std::equal_to<s td::string>, _Alloc =
std::allocator< int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h :887: instantiated from `void
__gnu_cxx::hash table<_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<cons t std::string, int> >, _EqualKey
= std::equal_to<s td::string>, _Alloc = std::allocator< int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h :381: instantiated from
`std::pair<__gn u_cxx::_Hashtab le_iterator<_Va l, _Key, _HashFcn, _ExtractKey,
_EqualKey, _Alloc>, bool> __gnu_cxx::hash table<_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<cons t
std::string, int> >, _EqualKey = std::equal_to<s td::string>, _Alloc =
std::allocator< int>]'
/usr/include/c++/3.2.2/ext/hash_map:171: instantiated from
`std::pair<__gn u_cxx::hashtabl e<std::pair<con st _Key, _Tp>, _Key, _HashFcn,
std::_Select1st <std::pair<cons t _Key, _Tp> >, _EqualKey, _Alloc>::iterat or,
bool> __gnu_cxx::hash _map<_Key, _Tp, _HashFcn, _EqualKey,
_Alloc>::insert (__gnu_cxx::has htable<std::pai r<const _Key, _Tp>, _Key,
_HashFcn, std::_Select1st <std::pair<cons t _Key, _Tp> >, _EqualKey,
_Alloc>::value_ type&) [with _Key = std::string, _Tp = int, _HashFcn =
__gnu_cxx::hash <std::string> , _EqualKey = std::equal_to<s td::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_stri ng<char,
std::char_trait s<char>, std::allocator< char> >&)'
make: *** [hm] Error 1
Jul 22 '05 #1
3 11885
"Mark" <ma************ *@nospamexcite. com> 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
Jul 22 '05 #2
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
Jul 22 '05 #3
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" <news-at-@michaelmellor-dot-.com> wrote in message
news:br******** **@newsg2.svr.p ol.co.uk...
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

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4594
by: Sabrina | last post by:
Can someone help? I have been trying to get the hash_map in C++ for .NET to work with strings and const char*. I am using the const char* as the key and a pointer to another class as the data type. I would like to be able to assign unique names to each key and allow the user to be able to search the hash_map to find that key and in so doing, retrieve the information that is being pointed to by the other class' pointer(data type). I can...
5
8633
by: peter_k | last post by:
Hi I've defined hash_map in my code using this: ------------------------------------------- #include <string> #include <hash_map.h> & namespace __gnu_cxx {
10
7920
by: g | last post by:
hello! I wanna replace an std::map<std::string,Services*> with hash_map.How I will do this? any link with examples? transactions.insert(std::pair<std::string,Services*>("Aservice",new xxxx)); transactions.insert(std::pair<std::string,Services*>("Vservice",new
9
4191
by: collection60 | last post by:
I've been developing some Unix based shell tools. They work fine on Linux and MacOSX. I want to compile them on Win32. But I can't get hash_map to compile. I tried downloading stl (and stlport) which is supposed to work in MSVC, but it doesn't, it just generates tons of errors for stuff that used to work just fine. Where do I get fts.h to compile and dirent.h compile?
1
9415
by: jayesah | last post by:
Hi All, I am developing my code with Apache stdcxx. I am bound to use STL of Apache only. Now today I need hash_map in code but as I learned, it is not available in Apache since it is not standard c++. Though it is available with GNU STL. The code module where I use hash_map will generate separate object file during compilation. This code module is also using STL string.
3
2949
by: newbie | last post by:
Same thing g++ complains when using hash_map<>, but is happy with map<--I understand hahs_map is not standardized, but since the compiler didn't complain something like 'hash_map<not defined', I suppose it's supported and should behave well when I used it correctly. BUT it didn't. Here is my code snippet: class MyKey { public: virtual void foo() { return; }
2
4288
by: Amit Bhatia | last post by:
Hi, I am trying to use hash maps from STL on gcc 3.3 as follows: #ifndef NODE_H #define NODE_H #include <ext/hash_map> #include "node_hasher.h" class Node; typedef hash_map<pair<int,int>, Node, Node_HasherLoc_Tree;
1
2836
by: joseysaac | last post by:
i have this code in a archive called ffont.h #ifndef FFONT_H_FILE #define FFONT_H_FILE #include "FBase.h" #include "FShape.h" #include <vector> #include <hash_map>
2
8165
by: marek.vondrak | last post by:
Hi, I am wondering if there are any functional differences between SGI's hash_map and tr1's unordered_map. Can these two containers be interchanged? What would it take to switch from hash_map to unordered_map? Thank you. -Marek
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9779
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5787
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.