STL container that works like vector of pointers?
Hi,
Is there an STL container class that works like a vector of pointers to avoid creating copies during sorting and re-arranging of the array? I suppose it's easy enough to just write vector<object*> and call delete on the objects manually, just wondering if there was somethign that encapsulated that functionality alreaedy...
Thanks!
And you can also use a container of smart pointers like boost::shared_ptr<> if boost::ptr_vector isn't quite right for your needs.
Or you can store objects that handle destruction automatically (smart pointers, or other RAII objects) in your vector.
If your goal is avoid creating copies, then the best solution is probably a container of pointers, but if your goal is both fast sorting and random access, then std::map might be the best compromise.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement