New to STL. Still trying to get a handle on the right way to use it.
I have a map storing pointers to other objects:
What is the correct way to make sure all the elements of the map are deleted?Code:class EwMultiTrace: public map<unsigned long, EwTrace*>
Will the map call "delete()" for each stored element?
Do I have to delete each element manually?
If so, how to do that?
... this does not work. Removing elements from underneath the iterator creates memory faults.Code:EwMultiTrace::~EwMultiTrace (void) { EwMultiTrace::iterator item; for (item = this->begin(); item != this->end(); item++) { EwTrace *trace = item->second; delete trace; } clear (); }
maps have no "front()" to feed you the first element until empty.
What's the right way to go?