Jump to content
  • Advertisement
Sign in to follow this  
TFS_Waldo

"#include map" creates A LOT of errors! =(

This topic is 4887 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

Okay, I finally got the idea of using std::map for the problem I was having yesterday, thanks to a few members (thanks) =). Well, sort of. When I "#include" the file "map" the compiler generates A LOT of errors in "map." Here are some of them: c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::multimap< _K,_Ty,_Pr,_A > &,const class std::multimap< _K,_Ty,_Pr,_A > &)' : could not deduce template argument for 'const class std::multimap< _K,_Ty,_Pr,_A > &' from 'const class std::basic_string< char,struct std::char_traits< char >,class std::allocator< char > >' But they are actually errors in the "< functional >" and "< xtree >" files included in "map." Can anyone help me out, please? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
The errors might look like they're in <map>, but that's just because that's where the template definitions are. The real error is most likely in your code. If you look a few lines further in the compiler errors, it may even tell you where. In any case, post your code.

Share this post


Link to post
Share on other sites
Okay, you are right. Sorry, I didn't think about that. =) Anyhow, I tried creating a blank project and including the file, and it worked fine. Here's my code:


// These lines are in the header file
typedef std::map<std::string, cmdfunc_t> Commands;
Commands m_pCmds;

// This is in the source file
m_pCmds.insert(std::make_pair(szCmdName, pCmdFunc));



Even that little bit of code causes the problem. But, when I comment the last line out, it works fine. What is wrong with that?

Share this post


Link to post
Share on other sites
Depending on your compiler, you can get errors like that if you forget to include the string header.

Share this post


Link to post
Share on other sites
Ho 'bout:


#include <map>

// These lines are in the header file
typedef std::map<std::string, cmdfunc_t> Commands;
typedef std::pair<std::string, cmdfunc_t> CommandsPair;
Commands m_pCmds;

// This is in the source file
m_pCmds.insert(CommandsPair(szCmdName, pCmdFunc));


Any better?

Share this post


Link to post
Share on other sites
Okay, everything is working out okay. But now, I have another problem. When I do:

m_pCmds.insert(CommandsPair(szCmdName, pCmdFunc));

I get an access violation. "The instruction at '0x10240eef' referenced memory at '0xcdcdcdcd'. The memory could not be 'read'." And when I debug, it goes back to "MEMCMP.ASM" (MSVCRTD.DLL). But when I comment out the "insert" line, it goes right through it. What could be causing this?

Share this post


Link to post
Share on other sites
Can you show the whole code, or is it too big?

If not how about the declaration of pCmdFunc and cmdfunc_t?

I am a little concerned that pCmdFunc is a cmdfunc_t*

so you would need either:


#include <map>

// These lines are in the header file

typedef std::map<std::string, cmdfunc_t*> Commands;

typedef std::pair<std::string, cmdfunc_t*> CommandsPair;

Commands m_pCmds;

// This is in the source file

m_pCmds.insert(CommandsPair(szCmdName, pCmdFunc));


OR

#include <map>

// These lines are in the header file

typedef std::map<std::string, cmdfunc_t> Commands;

typedef std::pair<std::string, cmdfunc_t> CommandsPair;

Commands m_pCmds;

// This is in the source file

m_pCmds.insert(CommandsPair(szCmdName, *pCmdFunc));



Share this post


Link to post
Share on other sites
I figured it out. It is because I had placed 'Commands m_pCmds;' in the class. Why it does not work I do not know. But I just made it global, and it works now! =)

Thank you all for your help. I'm sure I'll be back. ;)

Thanks again! =)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!