Jump to content
  • Advertisement
Sign in to follow this  
whiterook6

c++ std containers calling destructors

This topic is 3034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was reading the list reference on cplusplus.com and I found something: it says when I call clear or erase, for each element it removes it calls its destructor. so if I have
Object *o=new Object();
list<Object *> objects;
objects.insert(o);
objects.clear();
will o be deleted? or does it simply erase the pointer in the list? Because I don't want the list deleting my objects if it's not creating them too.

Share this post


Link to post
Share on other sites
Advertisement
The destructor of the object stored in the vector will be called. Your vector stores pointers, and pointers don't have empty an destructor (or no destructor at all, if you want). It doesn't do anything with the object being pointed to, because the vector cannot know what has to be done.

Share this post


Link to post
Share on other sites
Pointer variables don't have destructors. If you want that behavior, use a smart pointer like boost::shared_ptr.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!