Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

std::map exception

std::map exception

std::map exception

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:


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:


msg_map[ index ] = p_msg;  

I have edited the code to try to catch everything and now have the following:


Cstring t_string;
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):


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)

RE: std::map exception

Forgot a possible clue.  


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)

RE: std::map exception

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close