frek wrote: |
---|
Doesn't my code have appropriate tags now!? |
Looks like your code was derived from this MSDN page:
https://docs.microsoft.com/en-us/cpp/cpp/move-constructors-and-move-assignment-operators-cpp?view=vs-2019
1) Is the code fine or does it have any issue? |
It appears correct after a brief look.
This class provides no exception safety guarantees. An exception thrown during copy assignment, for example, will result in loss of user data.
Separately from the above, move operations should be
noexcept. Otherwise, some containers like
std::vector will fall-back to copying elements of type
A in order to meet their own exception-safety guarantees. If it exists,
swap should be
noexcept too.
std::exchange can often be used to simplify move special members.
Avoid
std::endl when
'\n' is sufficient.
endl flushes the stream buffer to its output device, which is a very expensive operation on many systems.
The statement
delete nullptr;
has no effect, so no test for
nullptr should be made before calling
delete.
The move constructor's member initializer list is out-of-order with respect to the data members. This isn't an error in this case, but a decent compiler will complain about it.
2) Is what I explained above correct, please? |
Yes, AFAICT