The move constructor is another constructor. If you have overloaded constructors, like any other functions that are overloaded, the choice of which constructor is called comes down to overload resolution rules. That is, when you build an object with Foo a(<some-expression>); There may be several possible constructors, and you need to choose.
The copy constructor takes one argument of type const Foo& . This lvalue reference type will be bound to any expression denoting a Foo object. The move constructor takes one argument of type Foo&& . This rvalue reference will only be bound to mutable r values. In fact, this overload will be preferable in the case of passing a variable value of r.
This means that in Foo a(<some-expression>); if the expression <some-expression> is a mutable value of r, a move constructor will be selected. Otherwise, the copy constructor is selected. Modified values โโof r usually appear when designating temporary objects (for example, the object returned by a function). You can also force an expression into an rvalue expression using std::move , for example Foo a(std::move(b)); .
source share