## Recommended Posts

if i use a boost::ptr_vector, the pointers in the ptr_vector delete, like shared_ptr (when the pointer is out of scope) or i need to do a std::vector<shared_ptr> to get that behavior thanks in advance!

##### Share on other sites
The former. This is largely the rationale for the existence of a boost::ptr_vector in the first place.

##### Share on other sites
The difference between ptr_vector<X> and vector<shared_ptr<X> > is that for the former, you need X to be clonable i.e. you need to provide new_clone() and delete_clone() functions if your hierarchy is polymorphic.

It's a little more work, but ptr_vector is often more efficient.

Another solution, if you'll permit the plug, would be to use a vector<value_ptr<X> >. value_ptr is designed to do the cloning for you. Arguably this is the easiest to use, though ptr_vector is likely more efficient.

##### Share on other sites
thanks for the help! @the_edd do you have an example of new_clone() and delete_clone() functions or some webpage with a good tutorial (i'm already read the reference in boost)

##### Share on other sites
I'm afraid I don't have an example as I've honestly never use any of boost's pointer containers. I imagine you just create an overload of new_clone() and delete_clone() to call your virtual copy function.

Perhaps something like:

base *new_clone(cont base &b){    return b.clone();}

I'm just going by what it says in the docs.