I don't seem to get why would you use the move assignment operator
:
CLASSA & operator=(CLASSA && other); //move assignment operator
over, the copy assignment operator
:
CLASSA & operator=(CLASSA other); //copy assignment operator
The move assignment operator
takes an r-value reference
only e.g.
CLASSA a1, a2, a3;
a1 = a2 + a3;
In the copy assignment operator
, other
can be constructor using a copy constructor
or a move constructor
(if other
is initialized with an rvalue, it could be move-constructed --if move-constructor
defined--).
If it is copy-constructed
, we will be doing 1 copy and that copy can't be avoided.
If it is move-constructed
then the performance/behavior is identical to the one produced by the first overload.
My questions are:
1- Why would one want to implement the move assignment operator
.
2- If other
is constructed from an r-value then which assignment operator
would the compiler choose to call? And why?