Yes, you must do this to avoid memory leaks. The best ways to do this is to create a vector of common pointers ( boost , C ++ TR1, C ++ 0x,)
std::vector<std::tr1::shared_ptr<A> > l;
or a vector of unique pointers (C ++ 0x), if the objects are not actually divided between this container and something else
std::vector<std::unique_ptr<A>> l;
or use boost pointer containers
boost::ptr_vector<A> l;
PS: Do not forget the virtual destructor, like @Neil Butterworth!
Cubbi source
share