473,803 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hash map question.

I've searched google for help with this one, but I haven't found it yet.
What I want is a hash map this looks like:
__gnu_cxx::hash _map<string, ArcNode> ArcNodeMap;

ArcNode is a class. It looks something like this:

class ArcNode
{
private:
// communication objects
int fdSocket;
public:
ArcNode();
~ArcNode();
int write(string);
int read(string&);
int open(string);
int state();

};

But when I try to compile I get:
In file included from main.cpp:3:
/usr/include/c++/3.2.2/bits/stl_pair.h: In instantiation of
`std::pair<cons t std::string, ArcNode&>':
/usr/include/c++/3.2.2/ext/stl_hashtable.h :266: instantiated from
`std::_Select1s t<std::pair<con st std::string, ArcNode&> >'
/usr/include/c++/3.2.2/ext/stl_hashtable.h :266: instantiated from
`__gnu_cxx::has htable<std::pai r<const std::string, ArcNode&>,
std::string, __gnu_cxx::hash <std::string> ,
std::_Select1st <std::pair<cons t std::string, ArcNode&> >,
std::equal_to<s td::string>, std::allocator< ArcNode&> >'
/usr/include/c++/3.2.2/ext/hash_map:101: instantiated from
`__gnu_cxx::has h_map<std::stri ng, ArcNode&,
__gnu_cxx::hash <std::string> , std::equal_to<s td::string>,
std::allocator< ArcNode&> >'
loggerbase.h:48 : instantiated from here
/usr/include/c++/3.2.2/bits/stl_pair.h:84: forming reference to
reference type
`ArcNode&'
/usr/include/c++/3.2.2/ext/hash_map: In instantiation of
`__gnu_cxx::has h_map<std::stri ng, ArcNode&,
__gnu_cxx::hash <std::string> , std::equal_to<s td::string>,
std::allocator< ArcNode&> >':
loggerbase.h:48 : instantiated from here
/usr/include/c++/3.2.2/ext/hash_map:182: forming reference to reference
type `
ArcNode&'
make: *** [logger] Error 1

I don't understand the reference to reference error message. Can
someone tell me what I'm doing wrong. A pointer to a tutorial that
discusses how to put objects into a hash_map would also be helpful.

Thanks,
Jim.

--
Jim Lynch
k4***@qsl.net

Jul 22 '05 #1
3 2814
Jim Lynch wrote:
I've searched google for help with this one, but I haven't found it
yet. What I want is a hash map this looks like:
__gnu_cxx::hash _map<string, ArcNode> ArcNodeMap;

<snip>

"hash_map" is not Standard C++. Please consult a group for your library.

- Pete
Jul 22 '05 #2
Jim Lynch wrote:
I've searched google for help with this one, but I haven't found it yet.
What I want is a hash map this looks like:
__gnu_cxx::hash _map<string, ArcNode> ArcNodeMap;
What you seem to have instead is
`__gnu_cxx::has h_map<std::stri ng, ArcNode&,
__gnu_cxx::hash <std::string> , std::equal_to<s td::string>,
std::allocator< ArcNode&> >'


(I might be wrong about this; you didn't post your code and I don't know
the gnu hash_map implementation well enough to be able to say for sure
that it doesn't go around adding ampersands willy-nilly like that. I'd
be surprised though.)

Don't use a reference type as the second template argument. Reference
types do not model the concepts required (Assignable for a start).

Ideally you could read about this at, for example,
http://www.sgi.com/tech/stl/PairAsso...Container.html

Perhaps best not to take the information from there too seriously in
this case - the basic situation appears to be:

(i) Pair Associative Container is a refinement of Container;
(ii) The value_type of a Container is required to be Assignable;
(iii) The value_type of a Pair Associative Container is required
to be std::pair <const key_type, data_type>;
(iv) std::pair <const key_type, data_type> is not Assignable.

Therefore 2+2=5, green is pink, and main returns void, QED.

--
Regards,
Buster.
Jul 22 '05 #3
Jim Lynch wrote:
I've searched google for help with this one, but I haven't found it yet.
What I want is a hash map this looks like:
__gnu_cxx::hash _map<string, ArcNode> ArcNodeMap;

Try std::hash_map<s td::string, ArcNode> ArcNodeMap;

Although hash_map is not part of the STL (as approved by the standard),
I know some implementations include it in this namespace. Give it a try.
ArcNode is a class. It looks something like this:

class ArcNode
{
private:
// communication objects
int fdSocket;
public:
ArcNode();
~ArcNode();
int write(string);
int read(string&);
int open(string);
int state();

};

But when I try to compile I get:
In file included from main.cpp:3:
/usr/include/c++/3.2.2/bits/stl_pair.h: In instantiation of
`std::pair<cons t std::string, ArcNode&>':
/usr/include/c++/3.2.2/ext/stl_hashtable.h :266: instantiated from
`std::_Select1s t<std::pair<con st std::string, ArcNode&> >'
/usr/include/c++/3.2.2/ext/stl_hashtable.h :266: instantiated from
`__gnu_cxx::has htable<std::pai r<const std::string, ArcNode&>,
std::string, __gnu_cxx::hash <std::string> ,
std::_Select1st <std::pair<cons t std::string, ArcNode&> >,
std::equal_to<s td::string>, std::allocator< ArcNode&> >'
/usr/include/c++/3.2.2/ext/hash_map:101: instantiated from
`__gnu_cxx::has h_map<std::stri ng, ArcNode&,
__gnu_cxx::hash <std::string> , std::equal_to<s td::string>,
std::allocator< ArcNode&> >'
loggerbase.h:48 : instantiated from here
/usr/include/c++/3.2.2/bits/stl_pair.h:84: forming reference to
reference type
`ArcNode&'
/usr/include/c++/3.2.2/ext/hash_map: In instantiation of
`__gnu_cxx::has h_map<std::stri ng, ArcNode&,
__gnu_cxx::hash <std::string> , std::equal_to<s td::string>,
std::allocator< ArcNode&> >':
loggerbase.h:48 : instantiated from here
/usr/include/c++/3.2.2/ext/hash_map:182: forming reference to reference
type `
ArcNode&'
make: *** [logger] Error 1


You need to post code here. This means that whatever you are trying to
do, it is trying to acquire a reference to a reference, which is illegal
in C++.

Jorge L.
Jul 22 '05 #4

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

Similar topics

5
2024
by: R. Rajesh Jeba Anbiah | last post by:
I could see that it is possible to have hash array using objects like var hash = {"a" : "1", "b" : "2"}; Couldn't still findout how to declare hash array in Array. var arr = new Array("a" : "1", "b" : "2"); doesn't work. Any hints? TIA -- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
8
5586
by: Michael B Allen | last post by:
I would like to know your preferences regarding a C API for a hash map. Specifically, when inserting a data item into a hash map there are two special cases that require consideration. 1) If two keys generate the same hash value should a comparison function be used to compare keys or should data items be compared? If data items are compared it is not necessary to store the keys with each entry which has an impact on question 2. 2) If...
2
3712
by: johnnyG | last post by:
Greetings, I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider to create a hash value from a string. The vb example outputs "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3" The cs example outputs "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8" for the string "password" Question: do the 2 applications use different automatic "salts" or "seeds" to...
12
7025
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
21
3232
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
6
2347
by: raymond | last post by:
Hi, I'm going out of my mind trying to figure this problem out. To save it, I figured I'd ask for some help :) I'm trying to create a hash with name/answer pairs. I retrieve a person's userid ($name) and their response ($answer) to a multiple choice question in a poll. I'm trying to store these into a simple hash:
2
2671
by: =?Utf-8?B?TW91dGhPZk1hZG5lc3M=?= | last post by:
How can I add an MD5 hash to XMLSerializer.Serialize without corrupting the content of the file; then how to read it back to verify is correct? I'd like to code up something (see below) that looks like this, but I'm not sure this is correct approach to the problem. Once I add the signature, the file won't test the same way again. I know I could add it to the bottom of the file, but then everyone would have to know my algorithm for...
3
2643
by: digz | last post by:
This is a simple case of a problem I am having with using char* in a hash_map, The code prints the size correctly( 3) and it should print three lines of output but is printing only two. I do not want to reserve space for the char* using new etc..( it will never will be deepcopied using strcpy etc..) ..it always holds an address. I know I am making some very fundamental mistake what am I missing here ?
5
8179
by: Jeff | last post by:
Lets say we have what I would call a "hash": var HASH =new Array(); HASH='first'; HASH='second'; HASH='third'; I'd like to return that as JSON data. Is there a direct way to do that?
2
5832
by: joe shoemaker | last post by:
I would like to convert url into md5 hash. My question is that md5 hash will create collision at 2^64. If you do long(value,16), where value is the md5 hash string, would value returned from long(value, 16) be unique as long as md5 hashed string is unique? when you move md5 hashed string to long, where will the collision occur, at anything hash = md5.new() hash.update("some_url_") value = hash.digest() value_in_int = long(value, 16)...
0
9700
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
9564
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,...
0
10546
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
10310
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...
0
10068
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...
1
7603
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
5498
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...
1
4275
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
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.