【发布时间】:2012-07-06 01:53:35
【问题描述】:
输入/输出流操作符理论上的关联性:
从左到右
(例如,根据这个:Sait Mary's University website
输入/输出流操作符关联性实践:
#include <iostream>
int func0() {
std::cout << "func0 executed" << std::endl;
return 0;
}
int func1() {
std::cout << "func1 executed" << std::endl;
return 1;
}
int func2() {
std::cout << "func2 executed" << std::endl;
return 2;
}
int main() {
std::cout << func0() << func1() << func2() << std::endl;
return 0;
}
输出(MSVCPP 2010、2012):
func2 executed
func1 executed
func0 executed
012
Press any key to continue . . .
此示例演示了以从右到左的顺序调用函数(尽管它们的值按预期从左到右打印)。
问题: 此代码示例如何与关于 LEFT TO RIGHT 执行的标准词相关联?为什么函数的执行顺序是从右到左?
【问题讨论】:
标签: c++ input operators associativity