Sign in to follow this  

c++ std containers calling destructors

Recommended Posts

whiterook6    124
I was reading the list reference on 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;
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
Brother Bob    10344
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this