"berthelot samuel" <sa**************@voila.fr> wrote:
I have a simple question. I use a stl vector of pointers on objects of
my own class, say Person:
vector<Person*> vectPerson;
vectPerson.push_back(new Person("Sam"));
when I call vectPerson.pop_back, do i need to take care of the pointer
by calling delete or does the pop method handle this for me ?
No, you will have to do it yourself. The pop methods just remove the
pointer from the vector. The std::vector class cannot know if it has to
delete the object that is being referenced by the pointer; depending on
the situation it may or may not be the appropriate thing to do. Rather
than using raw pointers, you may also opt for putting boost::shared_ptr
of the boost library (
http://www.boost.org/) in the vector. This way you
don't have to worry about ownership issues.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl