输入/输出流运算符理论上的结合性:
左到右
(例如,根据这个:圣玛丽大学网站 http://cs.smu.ca/~porter/csc/ref/cpp_operators.html
输入/输出流运算符结合性实践:
#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 . . .
此示例演示了按从右到左的顺序调用函数(尽管它们的值按预期从左到右打印)。
问题:此代码示例如何与有关从左到右执行的标准单词相关联?为什么函数执行按从右到左的顺序执行?
关联性定义了运算符 ((((std::cout << func0()) << func1()) << func2()) << std::endl);。然而,operator
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)