I don't get the 'chaining' part of this overload. Could someone explain it to me please ?
I've overloaded for this call: cout <<obj1<<obj2<<obj3; but it seems to only work on obj1.
Your function should look something like:
std::ostream& operator<<(std::ostream& os, const Obj& obj)
// do obj stuff
The bold parts are the things that enable chaning. It works like this.
Using your example, this is equivalent to what gets called.
std::ostream& tmp1 = operator<<(std::cout, obj1);
std::ostream& tmp2 = operator<<(tmp1, obj2);
std::ostream& tmp3 = operator<<(tmp2, obj3);
I hope you can now see why the return value is so crucial to the whole thing working.
Topic archived. No new replies allowed.