473,803 Members | 3,616 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 11881
"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
4589
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
8626
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
7911
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
4187
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
9404
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
2945
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
4284
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
2835
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
8152
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
9703
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
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6842
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
5500
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
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2970
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.