[gameprogrammer] Re: stl container doubts

  • From: Brian Barrett <brian.ripoff@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Mon, 13 Dec 2010 20:48:27 +0000

If you allocated the elements, then you need to delete them. If the
map allocated them then you don't need to worry. std::map::erase()
will call the destructor of the templated types. If these are raw
pointers, then the destructor is a "no-op".

You could use a smart pointer, or use boost::ptr_map.

To be exception safe, you should first try to erase the object from
the map, so that there is no possibility of having an invalid pointer
in the map.

On 13 December 2010 15:28, Roger Durañona Vargas <luo_hei@xxxxxxxx> wrote:
> I have a doubt about stl containers, like std::map. Currently, to remove
> an element I first delete the element, so it is properly destroyed, and
> then I call erase, to remove the element place in the map. Is that
> procedure correct? Or erase should take care of calling the destructor
> (wheich I think is not happening)?

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: