Subj : chaining cout with a changing object To : borland.public.cpp.borlandcpp From : "Taras Kentrschynskyj" Date : Wed Sep 10 2003 04:12 pm One of my students at the Royal Institute of Technology in Stockholm, Sweden, draw my attention to the following: He had written an integer stack class (linked list implementation) with a pop operation returning the top item (data in the first node of the list, deleting this node after setting the top pointer to it's next), and tried the following: cout << mystack.pop() << mystack.pop() << mystack.pop(); If he had pushed 1, 2 and 3 on the stack, in that order, the output was, unexpectedly: 123 looks like a recursive call.. whereas the following: cout << mystack.pop(); cout << mystack.pop(); cout << mystack.pop(); of course gave the expected output: 321 I tried to track the first alternative, and found out that all three function calls are accomplished before any output in the chained statement. The same is true if you use another member function that doesn't change the object, e g get(int i), returning item no i in the stack. In this case, however, if you chain cout: cout << mystack.geti(1) << mystack.geti(2) << mystack.geti(3); the output comes in the chain order, not the reverse order as with the pop function. So, what is going on? How are the three return values saved in the chained statement? How does the pointer settings affect the order of the chained output? .