Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / All enums in map are 0

Author
Message
Manfred
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: Austria
Posted: 27th Jul 2008 14:14
Hello guys,

I have a std::map with a char* as key and an enum as value. If I print the values uf the enum I get the correct list from 0 to ...
But if I want to get the enum value by using the map with the key all the output values are 0.



Does anyone have an idea what I am doing wrong (the above listing is just the relevant part of the code)?

Thanks and best wishes.

Casting, the art of manipulation; further information every day in TV.
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 28th Jul 2008 20:20 Edited at: 28th Jul 2008 20:21
Manfred
16
Years of Service
User Offline
Joined: 23rd Jun 2008
Location: Austria
Posted: 28th Jul 2008 23:20
I found a way to get this working: Instead of using const char* as key type, I use std::string.
Well, I don't know why this doesn't work with const char*. However in this case a solution is as good as an explanation.
Enumerating the list manually doesn't solve the problem.

Casting, the art of manipulation; further information every day in TV.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jul 2008 23:42
When you use a pointer as the index into a map, the pointers are compared against each other, not what they point to.

You've seen one alternative, but another is to write your own 'less' function and use that on the map:


(The reason for making my own copy of the string is that sometimes the compiler will detect that the strings are the same and use a single address for all of them - I wanted to ensure that didn't happen and give an accidental match)

Login to post a reply

Server time is: 2024-11-20 17:41:22
Your offset time is: 2024-11-20 17:41:22