0

Can somebody explain this code:

void Move(Person& lhs, Person&& rhs)
{
    lhs = rhs; //invokes copy assignment instead of move assignment
    //lhs = (Person&&) rhs; //casting to && invokes move assignment.
}
  • 3
    Anything with a name is automatically lvalue, and this includes `rhs`. – HolyBlackCat Dec 25 '22 at 07:38
  • `rhs` is an `lvalue`. See dupe: [why named rvalue ref is an lvalue expression](https://stackoverflow.com/questions/56316766/why-is-a-named-rvalue-reference-an-lvalue-expression) – Jason Dec 25 '22 at 07:41
  • ... so to get what you want, you have to do: `lhs = std::move (rhs);` (which is what `std::move` is for). – Paul Sanders Dec 25 '22 at 08:14

0 Answers0