#### Archived

This topic is now archived and is closed to further replies.

# The STL map container with MSVC

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

## Recommended Posts

I'm having problems getting this container to work with MSVC 6, I have it declared properly (I think), like this... "std::map > TestMap;", and I have tried many different variations of the above, but they all seem to have no effect. When I compile, I get a good page full of warnings with weird symbols in them... They are more or less impossible to interpret, and I'm sure they're meaningless to the real cause of the problem. Anyone else have this problem? If it makes a difference, I'm declaring the map in a header file... (Although it IS being declared properly, no other variables (or STL containers) give me any problems) Any help will be appreciated, thanks in advance! -------- Heavy Delta (Quake 3 Mod) - http://www.q3seek.com/heavydelta/ (We're currently looking for mappers and skinners!) AllAdvantage.com - Make money for surfing, it does work, I got a few checks already Edited by - Vore on 5/6/00 4:57:29 PM

##### Share on other sites

Hmm....the warnings are pretty much normal. You can use the pragma directive to disable them, or you can just ignore them if you prefer.

What errors are you getting?

All you should need to do is to include the <map> header file, and then the using namespace std statement. e.g.

#include <map>

using namespace std;

map<key,data> TestMap;

HTH,

-z

##### Share on other sites
The warnings are ALWAYS there in Debug mode in MSVC 6. I believe you are talking about warning 4786, which involves the decorated type name (with debug info added) exceeding the 255 character maximum. This is NOT a compiler error, nor will it affect your code in any way, but it IS extremely annoing. To allieviate this problem I''ve taking to begining each .cpp (not header) file with the following pragma:

#pragma warning(disable : C4786)
// double check the exact format in you MSDN library

which completly turns off that warning message, but ONLY that warning. Which in my experience is the ONLY warning which is absolutely ALWAYS useless. All other warnings I feel should at least be read, and usually eliminated, using proper casting etc...

now. If you are also getting errors, I''m not exactly sure why. I do the following:

// include directive
#include

// typedef
typedef std::map ThisMapType

// variable declaration
ThisMapType testMap

// usage example
... code ...
for(ThisMapType::iterator pos = testMap.begin();pos != testMap.end();++pos)
{
// do stuff like
if(pos->first == "ABBA")
{
}
}
... more code ...

The only reason I gave such a detailed example above, was to explain the reason I usually use a typedef for my particular map (and any container) types. I use typdefs when reasonable, because they REALLY help when writing many loops and functions which need iterators of your container type. Their''s very little room for error writing MyMapType::iterator, but there is a lot of run for silly mistakes doing this: std::map::iterator, because you might differ the type by some small insignificant thing (like int or long) and then find when you change platforms it doesn''t run.

Good luck, hope i''ve been able to help

##### Share on other sites
Sorry, I have not yet learned how to type code into this damn message board without it fucking with the underscores, and angle brackets. If you know how, please post it here and I''ll fix my previous post.

Thanks

##### Share on other sites
This character: <
Is written: &lt;

This character: >
Is written: &gt;

##### Share on other sites
Thanks Xai (and Mordell), that definately was the warning I was getting, and the pragma worked... There was just one small thing you said wrong, you wrote

#pragma warning(disable : C4786)

but it shouldn''t have the C infront of 4786....

Anyways, thanks again, it''s working nice now, hopefully MS will clean that up soon!

--------
Heavy Delta (Quake 3 Mod) - http://www.q3seek.com/heavydelta/
(We're currently looking for mappers and skinners!)

AllAdvantage.com - Make money for surfing, it does work, I got a few checks already

##### Share on other sites
Ugh... Now I''m getting a linker error, anyone know what library to link with for the map container?

##### Share on other sites
You shouldn''t need any extra lib files for std::map. What error is it exactly?

##### Share on other sites
dpmessages.obj : error LNK2001: unresolved external symbol "protected: static class std::map,class std::allocator > DPMessage_Maker::MakerRegistry" (?MakerRegistry@DPMessage
_Maker@@1V?$map@HPAVDPMessage_Maker@@U?$less@H@std@@V?\$allocator@PAVDPMessage_Maker@@@3@@std@@A)
Debug/Darthmoth.exe : fatal error LNK1120: 1 unresolved externals

Is the error... Any ideas?

##### Share on other sites
Looks like you declared "MakerRegistry" as a class static
and didn''t define it anywhere.

when you do:

class foo { static bar baz;}

You must declare the ''baz'' object somewhere:

bar foo::baz;

-- Pryankster

• 17
• 10
• 10
• 12
• 21