Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > C++ STL Trouble (map)

C++ STL Trouble (map)
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2001
Location: College
Status: Offline
Reply With Quote
Jan 20, 2004, 11:58 PM
 
I have no idea why, but this isn't working:

In my .h file:
Code:
class SymbolModule { public: <snip> SymbolModule() { entity_map = new map<const char*, EntityAttribute>(); } map<const char*, EntityAttribute> Get_Map(); private: map<const char*, EntityAttribute>* entity_map; };
and in the corresponding .cpp file:

Code:
map<const char*, EntityAttribute> SymbolModule::Get_Map() { /* this line */ return *entity_map; // <--- this is the line }
Whenever, and however I call this function, it stops on the indicated
line and exits "due to signal 10 (SIGBUS)."
Microsoft knows what's best for you, so keep quiet, open your wallet and be a team player.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jan 21, 2004, 02:51 AM
 
I suspect that this is dying in the copy constructor for your map. Without seeing EntityAttribute, I'm not sure why, but here's what I think is happening: Your GetMap method is returning a temporary map variable that is a copy of your class's map variable. So, when you call GetMap, your map is copied to a temp variable (using the copy constructor, which will call the copy constructor for EntityAttribute). This temporary variable is then assigned to whatever calls GetMap.

This is almost certainly not what you want. You probably want to return the class's map for read/write access, in which case, you should either return the map by reference (be careful with this route), or return a pointer to the map.

Hope this helps.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Fresh-Faced Recruit
Join Date: Aug 2001
Location: College
Status: Offline
Reply With Quote
Jan 21, 2004, 11:47 PM
 
This is gonna sound a little stupid, but...

I was calling the function off of an iterator... more specifically rend() which was empty. I wanted rbegin().

Anyway, smeger, thanks for the help.
Microsoft knows what's best for you, so keep quiet, open your wallet and be a team player.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2