为什么首先调用函数g()
?我将g()
定义为初始化程序列表中的第二个元素。初始化程序列表中元素的评估顺序
以下是与标准相关的引用,与初始化列表有关吗?
§8.5.4.4:在一个支撑-INIT-列表的初始化列表中, 初始化子句,包括任何从包膨胀导致 (§14.5.3),按以下顺序进行评价在其中出现。
#include <iostream>
#include <vector>
int f() { std::cout << "f"; return 0;}
int g() { std::cout << "g"; return 0;}
void h(std::vector<int> v) {}
int main() {
h({f(), g()});
}
输出:
gf
您的代码不包含任何初始值设定项列表。 –
在C++中未指定函数参数的评估顺序。 – 101010
http://stackoverflow.com/questions/621542/compilers-and-argument-order-of-evaluation-in-c –