Jump to content
  • Advertisement
Sign in to follow this  
Erondial

std::map

This topic is 3252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I swear to god, I must be doing something wrong, but for the life of me, I can't think of what it could be. My output is: Error: INTADD 0 2 WTF?! and my code is:
std::map<char*, FunctionInformation*>::iterator Temp;
Temp = ParentManager->FunctionMap.begin();
Error("Error: %s %d %d\n", "", (*Temp).first, (*Temp).second->Action, (*Temp).second->ArgumentCount);
if (ParentManager->FunctionMap.find("INTADD") == ParentManager->FunctionMap.end())
    Error("WTF?!\n\n","");
It's outputting as it should be, except for the WTF, which should most definitely not be there. For some reason, neither find, nor the accessor can get me anything that's not NULL. Anyone have any idea what's going on?

Share this post


Link to post
Share on other sites
Advertisement
When you use char * as the key of a map, you end up comparing pointers. As a comparison, what would you expect to happen if you had int * as the key, or even void * as the key?

What you really want is you want std::string as your key. In fact, you almost always want std::string in place of char * in C++.

Share this post


Link to post
Share on other sites
Agh. Okay. I was wondering about that, but for some reason char* strings always seem somewhat magical to me, and I subconsciously think they'll always work out.

Thanks! I appreciate it :p

Share this post


Link to post
Share on other sites
Some refactoring hints:


typedef std::map<std::string, FunctionInformation*> info_map;
info_map& info = ParentManager->FunctionMap;
info_map::iterator temp = info.begin();
Error("Error: %s %d %d\n", "", temp->first, temp->second->Action, temp->second->ArgumentCount);
if (info_map.find("INTADD") == info_map.end())
Error("WTF?!\n\n","");

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!