How to store a vector of pointers

Discussion in 'C' started by ever_thus, May 7, 2007.

  1. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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).
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  3. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    Which is what I'm doing at the moment. This is, however, error-prone.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice