<分区>
假设我有这个类:
struct A
{
A(int, int, int) {}
};
然后我这样初始化它:
A{ a(), b(), c() };
其中函数a()
、b()
和c()
都返回int
。应该在 b()
之前调用 a()
和在 c()
之前调用 b()
吗?
我对标准 (8.5.4 [dcl.init.list] p4) 中的以下段落感到困惑:
Within the initializer-list of a braced-init-list, the initializer-clauses, including any that result from pack expansions (14.5.3), are evaluated in the order in which they appear. That is, every value computation and side effect associated with a given initializer-clause is sequenced before every value computation and side effect associated with any initializer-clause that follows it in the comma-separated list of the initializer-list. [ Note: This evaluation ordering holds regardless of the semantics of the initialization; for example, it applies when the elements of the initializer-list are interpreted as arguments of a constructor call, even though ordinarily there are no sequencing constraints on the arguments of a call. — end note ]
根据引用,函数将按它们出现的顺序被调用,但是当我用我的编译器 (g++-4.8.1) 测试它时,它不成立。我是不是误会了什么?