A class of mine has this member: std::vector<Foo*> foo;
where Foo
is a class.
Then somewhere in my code, foo.push_back(new Foo);
is called.
If I wanted to properly delete this, would foo.erase(foo.begin());
deallocate the contents of the allocated object or only delete the pointer to it?
Last edited on
No, everything allocated with new
must be destructed with delete
( unless you are using smart pointers of some kind )
It will _not_ call Foo's destructor, nor will it delete the pointer (free the memory).
This is the purpose of boost::ptr_vector in the boost.ptr_container library.