Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

std::map exception

Status
Not open for further replies.

bkelly13

Programmer
Aug 31, 2006
98
US
Windows XP Pro, Visual Studio 2008.
I created some test code at home using std::map (Windows 7, visual studio 2008) and it worked fine. Back at work I cannot get past step 2. (step 1 is write code and compile) It appears that the map delcaration is okay and the code compiles, but when I do anything with the map an exception is thown. Here is the declaration:
Code:
 std::map< int, MSG_STRUCT * > msg_map;
std::map< int, MSG_STRUCT * >::iterator msg_iter;
MSG_STRUCT * p_msg;

The structure is defined earlier in the same h file. In the code the exception was thrown when I tried either of these:
Code:
 msg_map.clear(); 
msg_map[ index ] = p_msg;

I have edited the code to try to catch everything and now have the following:
Code:
Cstring t_string;
try
{
msg_iter = msg_map.begin();  // an arbitrary selection
}
{
catch( std::exception & e )
{
   t_string.Format( L" %s ", e.what() );
}
catch( ... )
{
   t_string.Format ( L"huh?");
}

when I step through with the debugger an expception is thrown. I wind up here in file xtree (opened by VS):
Code:
iterator begin()
{
return (TREE_ITERATOR( )_Lmost() ) );
}

I found the "std::exception & e" with some searches and thought that with that catch, followed by catch(...) I would have a chance it figuring out what is wrong. Something is fundamentally wrong with my declaration but I don't know where to look.

My work computer is in an isolated room and I cannot cut and paste. Please excuse any typos that I have probably made. The code compiles and starts up, the structure is created using the pointer and populated with some data, then when I attempt to do anything with the map, the exception is thown.
I need some clues.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
Forgot a possible clue.
Code:
 map_size = msg_map.size();
returns a value of 10 before I do anything to the map. Is that unusual?

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 
It should return 0.

In the early days, you couldn't clear a map if there was nothing in it. That was fixed about 10 years ago.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top