gpt4 book ai didi

c++ - 继承显式构造函数 (Intel C++)

转载 作者:可可西里 更新时间:2023-11-01 16:09:26 26 4
gpt4 key购买 nike

英特尔 C++ 编译器(版本 16.0.3.207 Build 20160415)似乎在使用 using 继承基类的构造函数时删除了 explicit 说明符。这是错误吗?

struct B
{
explicit B(int) { }
};

struct D : B
{
using B::B;
};

B b = 1; // Not OK, fine
D d = 1; // Not OK with Microsoft C++ and GCC, but OK with Intel C++

最佳答案

我认为标准中的适当措辞如下(n4296,12.9 继承构造函数):

...

The constructor characteristics of a constructor or constructor template are

(2.1) — the template parameter list (14.1), if any,

(2.2) — the parameter-type-list (8.3.5), and

(2.3) — absence or presence of explicit (12.3.1).

For each non-template constructor in the candidate set of inherited constructors other than a constructor having no parameters or a copy/move constructor having a single parameter, a constructor is implicitly declared with the same constructor characteristics unless there is a user-declared constructor with the same signature in the complete class where the using-declaration appears or the constructor would be a default, copy, or move constructor for that class.

...

所以它很可能是英特尔 C++ 编译器中的错误。

关于c++ - 继承显式构造函数 (Intel C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41495401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com