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

Started by
8 comments, last by TFS_Waldo 18 years, 8 months ago
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!
:==-_ Why don't the voices just leave me alone?! _-==:
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.
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?
:==-_ Why don't the voices just leave me alone?! _-==:
Depending on your compiler, you can get errors like that if you forget to include the string header.
Hey, I'm sorry. I forgot all about specifying my compiler. I am using Visual C++ 6.0. If that helps any. =)
:==-_ Why don't the voices just leave me alone?! _-==:
Ho 'bout:

#include <map>// These lines are in the header filetypedef std::map<std::string, cmdfunc_t> Commands;typedef std::pair<std::string, cmdfunc_t> CommandsPair;Commands m_pCmds;// This is in the source filem_pCmds.insert(CommandsPair(szCmdName, pCmdFunc));


Any better?
Gary.Goodbye, and thanks for all the fish.
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?
:==-_ Why don't the voices just leave me alone?! _-==:
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 filetypedef std::map<std::string, cmdfunc_t*> Commands;typedef std::pair<std::string, cmdfunc_t*> CommandsPair;Commands m_pCmds;// This is in the source filem_pCmds.insert(CommandsPair(szCmdName, pCmdFunc));


OR
#include <map>// These lines are in the header filetypedef std::map<std::string, cmdfunc_t> Commands;typedef std::pair<std::string, cmdfunc_t> CommandsPair;Commands m_pCmds;// This is in the source filem_pCmds.insert(CommandsPair(szCmdName, *pCmdFunc));



Gary.Goodbye, and thanks for all the fish.
Quote:'0xcdcdcdcd'


Uninitialized memory.
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! =)
:==-_ Why don't the voices just leave me alone?! _-==:

This topic is closed to new replies.

Advertisement