STL container that works like vector of pointers?

Started by
3 comments, last by JohnBolton 18 years, 4 months ago
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!
Advertisement
Not in the STL. But Boost offers boost::ptr_vector.
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.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement