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