oh yeah, true, I'm sorry, in my example there is no deep copy.
I can see that that move semantics is doing the shallow copy. Consider the following sample: |
nah, the move semantics transfers the ownership of the data from one object to the other. basically the pointer of the new object is set to the data from the old and the old is set to nullptr
Do you allways want B-objects to have a vector of A's for themselves without any other objects acessing them?
- if yes: simply don't use pointers, just store the data in a vector of A's
otherwise you have to better describe the behaviour you want.
If you only want deep copies don't use pointers
if you only want shallow copies only use shared_ptrs
if you want both of them you have to be more preciese about when you want to do what.
I found many developers abusing pointers because they thought "it would be better to have the memory managed by pointers so they can easily be shared" but that often resulted in bad code.