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

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

## 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 on other sites
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 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 on other sites
Depending on your compiler, you can get errors like that if you forget to include the string header.

##### Share on other sites
Hey, I'm sorry. I forgot all about specifying my compiler. I am using Visual C++ 6.0. If that helps any. =)

##### Share on other sites
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?

##### 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 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 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));

##### Share on other sites
Quote:
 '0xcdcdcdcd'

Uninitialized memory.

##### 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! =)

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 11
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632148
• Total Posts
3004451

×