what is return type of assignment operator?

The standard correctly defines the return type of an assignment operator.
Actually, the assignment operation itself doesn’t depend on the return value – that’s why the return type isn’t straightforward to understanding.

The return type is important for chaining operations.
Consider the following construction: a = b = c;. This should be equal to a = (b = c), i.e. c should be assigned into b and b into a. Rewrite this as a.operator=(b.operator=(c)). In order for the assignment into a to work correctly the return type of b.operator=(c) must be reference to the inner assignment result (it will work with copy too but that’s just an unnecessary overhead).

The dereference operator return type depends on your inner logic, define it in the way that suits your needs.

Leave a Comment