<p><code>operator<<</code> associates left-to-right, which means that the first statement</p>
<pre><code>std::cout << std::hex << centered(a,cout) << std::dec;
<p>is equivalent to </p>
), centered(a, cout)
<p>With this syntax, it appears that <code>operator<<(std::cout, std::hex)</code> and <code>centered(a, cout)</code> are both parameters to <code>operator<<</code>. Hence, as per the standard, their order is unspecified: It's not Undefined Behavior, but the compiler is free to choose the order it prefers.</p>
<p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26910675/operator<<%20chaining%20and%20function%20call%20order/26911212">Stack Overflow</a>.</p>
Get New Tutorials Delivered to Your Inbox
New tutorials will be sent to your Inbox once a week.