vendredi 26 juin 2020

Create Deep copy of boost::shared_ptr

I have two vectors of shared_ptr;

typedef boost::shared_ptr <A> someptr;
std::vector<someptr>src;
std::vector<someptr>dest;

If I copy using dest=src,both the vector elements are sharing the same memory location which increases the ref count of pointer.They both point to common location and any change in elements of one vector will affect the other.I understood that this is a shallow copy and it is the intended behaviour.

But if I want to create a deep copy for dest vector elements with different memory location ,what should I do?How to achieve this?

Does boost have a function to achieve this?

Aucun commentaire:

Enregistrer un commentaire