How to copy full object behind boost::shared_ptr<T>
: are there memcopy options (just create memory clone), or we shall create copy constructor?
You need a copy constructor or an operator=
that will perform the deep copy.
boost::shared_ptr
cannot know your object's structure to do this for you. Neither can a "memory clone" operation.
Of course, this is only for objects, that need an explicitly defined copy constructor / operator=
and the "trivial" ones make a shallow copy.
If you know the exact type of the object, then you should use a copy constructor or copy assignment operator.
If the objects is an instance of a class in an inheritance hierarchy, and you do not know the exact type of the object, then you should use a virtual clone function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With