just a question about the list.pop_front function

Hello everyone.

For a project i have to store several objects on a list<myType*>
I was just wondering if the member function list.pop_front will just remove my objects for the list, or totally destroy my object.
Will the member function list.pop_front eventually gonna call the destructor of my object ?

i guess it wont be it's just to be sure.

Thanks for your future answers.
pop_front will remove and destroy the myType pointer. It does nothing to the object that the pointer points so if you want to delete it you will have to do it yourself.
Last edited on
Ok, thank you very much for your response and your reactivity !
If your compiler supports it, you can use smart pointers like std::unique_ptr so they can be automatically cleaned up when they exit the list.

1
2
3
4
5
6
7
8
typedef std::unique_ptr<int>  intptr;

std::list<intptr> mylist;

mylist.push_back( intptr( new int(5) ) );

mylist.pop_back();  // delete is automatically called on the object.  You do not have
   // to do it manually 

Topic archived. No new replies allowed.