Why should the assignment operator return a reference to the object?

The usual form returns a reference to the target object to allow assignment chaining. Otherwise, it wouldn’t be possible to do:

Foo a, b, c;
// ...
a = b = c;

Still, keep in mind that getting right the assigment operator is tougher than it might seem.

Leave a Comment