I think this is normal if you return by value in the overloaded assignment operator, that is, due to the associativity of the assignment operator. consider this:
int a = b = c = 3;
here the associativity is as follows: (A = (b = (c = 3)))
but consider the operation iostream cout <x <y <z;
here the associativity is as follows: (((cout <x) <y) <z);
you can see that x will be printed first, so if you return by value when the <<operator is overloaded, the return value will not be an “lvalue”, while returning by refrence is an lvalue, so cascading <<operator can be achieved.
another point, the copy constructor will be called if you return by value. (which does not match return with refrence)
pankaj kushwaha
source share