ostream chaining, output order
The behavior of your code is unspecified as per the C++ Standard. Explanation The following (I removed std::endl for simplicity) std::cout << “Hello, world!” << print( std::cout ); is equivalent to this: operator<<(operator<<(std::cout, “Hello, World!”), print(std::cout)); which is a function call, passing two arguments: First argument is : operator<<(std::cout, “Hello, World!”) Second argument is : … Read more