This idiom exists to enable a chain of function calls:
int a, b, c; a = b = c = 0;
This works well for int s, so it makes no sense to do this not for custom types :)
Similarly for stream operators:
std::cout << "Hello, " << name << std::endl;
works the same way
std::cout << "Hello, "; std::cout << name; std::cout << std::endl;
Due to the idiom return *this , you can link as the first example.
source share