构造函数的参数求值顺序

构造函数的参数求值顺序

本文介绍了构造函数的参数求值顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

说我有这个课程:

struct A
{
  A(int, int, int) {}
};

,我将其初始化为:

A{ a(), b(), c() };

其中函数 a() b() c()都返回 int 。应该在 b() b() a() c()之前的$ c>?

Where the functions a(), b() and c() all return int. Should a() be called before b() and b() before c()?

我对标准中的以下段落感到困惑(8.5.4 [dcl.init.list] p4):

I am mystified by the following paragraph from the standard (8.5.4 [dcl.init.list] p4):

根据引号,将按出现的顺序调用这些函数,但是当我使用我的编译器(g ++-4.8.1),没有保存。我误解了吗?

According to the quote, the functions would be called in order they appear, but when I've tested this with my compiler (g++-4.8.1), it did not hold. Have I misunderstood something?

推荐答案

这是(由于(链接)。您引用的段落通常适用于列表初始化,其中条款在第8.5.4 / 1段中非常清楚地定义:

This is a bug in GCC (thanks to Casey for the link). The paragraph you quoted applies in general to list initialization, where the terms are defined pretty clearly in paragraph 8.5.4/1:

没有理由相信这仅适用于初始化程序列表构造函数的调用。另外,您引用的段落中的注释澄清了:

There is no reason to believe this should apply only to the invocation of an initializer list constructor. Also, the note in the paragraph you quoted clarifies that:

这篇关于构造函数的参数求值顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:43