Skip to main content
gamedev.net
🔒 Locked

std::map questions.

Started by c_olin Jan 16, 2008 at 11:48 PM 2 replies 600+ views
Original Post
c_olin
c_olin
Let's hypothetically say I have an std::map of pointers: std::map _settings; How would I free all of the pointers in the map? I've tried iterating through the map and deleting each map but the std::map iterators do not work the same as std::list iterator. I'm predicting people suggest smart pointers...
Hollower
Hollower
Quote:
Original post by c_olin
I'm predicting people suggest smart pointers...

Now they don't need to. :)

The elements of a std::map are actually std::pair objects. These have public members named first and second. first is the key, second is the value. Try your iterate-delete routine again but this time write:

delete iter->second;

c_olin
c_olin
Awesome... works great, thanks.
Zahlman
Zahlman
Or you could use boost::ptr_map. :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.