I am new to C++, and just learning about move semantics. So from what I understand, using the move constructor I can do something like
MyObj obj1;
MyObj obj2 = std:move(obj1);
And we have to define our own move constructor that cleans up obj1 etc.
It seems we can instead have obj2
be a reference to obj1
if we know that obj1
will not be destroyed before obj2
is done being used. But otherwise, can't we just use an unique_ptr
instead? Such that we just create an unique pointer for obj1 and then pass this pointer instead of trying to move the object?
Is there some cases I am not considering?