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

标签 c++ c++11 using-declaration icc explicit-constructor

英特尔 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/

相关文章:

c++ - 了解析构函数

c++ - 通过 using-directive 在 using-declaration 中查找名称

c++ 使用声明、作用域和访问控制

c++ - `>>>` 如何在 C++0x 中进行词法分析?

c++ - 覆盖 ADL 选择的重载

c++ - 一个 C++ 计时器阻塞了我的整个类(class)?

c++ - GCC 8 无法编译 make_shared<volatile int>()

c++ - 如何从一个类调用另一个类的函数而不需要继承

c++ - 智能指针应该/可以通过函数中的引用传递吗

c++ - 具有多种返回类型的函数