jeudi 26 mars 2015

Why move assignment operator should return reference to *this

Can someone explain why the move assignment operator is (usually) declared as



Foo& operator=(Foo&&);


Why return a reference and not e.g. the object itself? I understand why we want this for the regular assignment operator, due to associativeness rules as (a=b)=c being broken if not returned by reference, but why is this the case when the RHS is a rvalue (xvalue/prvalue)?


Aucun commentaire:

Enregistrer un commentaire