So to sum up, even if the string operator returned a string, then if we wanted to invoke the assignment operator again using the returned string, I don't see how it would matter since the argument for the operator knows we want to use it as a reference anyway.
To illustrate the difference, run this test program:
Code:
#include <iostream>
class X
{
public:
X()
{
std::cout << "Default ctor called." << std::endl;
}
X(const X& other)
{
std::cout << "Copy ctor called." << std::endl;
}
X& operator=(const X& other)
{
std::cout << "Copy assignment operator called." << std::endl;
return *this;
}
~X()
{
std::cout << "Dtor called." << std::endl;
}
};
int main()
{
X a, b, c;
a = b = c;
}
Now, edit the copy assignment operator to make it return by value instead of by reference, then run the program again and observe the difference.