How to store a vector of pointers

ever_thus's Avatar, Join Date: Jan 2007
Contributor
What is the best way to store pointers in C++. The number of pointers is dynamic, so an array is not feasible. C++'s vector is not the obvious solution, as deleting anything off the vector would cause a memory leak. Subclassing vector to properly delete pointers is not feasible either, as vector's destructor is not virtual. Is there any other option to creating my own vector (a proper pain to do).
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
If you erase a member of the vector, you'd definitely have to delete the (dynamically allocated) pointer first. I'm not sure how that's any more of a pain than creating your own vector class. You're right about not subclassing an STL container. I don't know of an easy way out.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
Quote:
If you erase a member of the vector, you'd definitely have to delete the (dynamically allocated) pointer first.
Which is what I'm doing at the moment. This is, however, error-prone.