Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to store a vector of pointers (http://www.go4expert.com/forums/store-vector-pointers-t4218/)

ever_thus 8May2007 00:23

How to store a vector of pointers
 
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).

DaWei 8May2007 01:05

Re: How to store a vector of pointers
 
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.

ever_thus 8May2007 08:16

Re: How to store a vector of pointers
 
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.


All times are GMT +5.5. The time now is 01:55.