c++auto-ptr

Reference to a subset of a container object


i have a quick question about having a reference to a subset of a collection. Consider i have a vector of objects. Now I want to create another vector which is a subset of this vector, and I dont want to create a copy of the subset of objects.

One of the ways I was thinking about is creating a vector<auto_ptr<MyClass> >. Is this a good approach? Please suggest if you think any other containers or idioms or patterns would help in this case. Thank you


Solution

  • No ! See : Why it is wrong to use std::auto_ptr<> with STL containers ?

    Now, as an alternative, you could store raw pointers or boost::shared_ptr depending on your needs.