我正在阅读有关Inheriting constructors here的文档。这里有一个例子:继承构造函数和默认构造函数
struct B1 {
B1(int);
};
struct D1 : B1 {
using B1::B1;
// The set of inherited constructors is
// 1. B1(const B1&)
// 2. B1(B1&&)
// 3. B1(int)
// D1 has the following constructors:
// 1. D1()
// 2. D1(const D1&)
// 3. D1(D1&&)
// 4. D1(int) <- inherited
};
因此它写清楚D1 has the following constructors: D1()
,即默认构造函数。但是,当我试图创建一个对象:
D1 d;
而且我有一个错误use of deleted function 'D1::D1()'
。这是文档中的错误还是我误解了某些内容?
我用C++ 14试过gcc。
@POTEMKINDX您忘记在'main()'中添加'D1 d;'。如果你确实看到它不起作用:http://coliru.stacked-crooked.com/a/220ea673061325fd – NathanOliver
@POTEMKINDX你没有调用导致[error]的构造函数(http://ideone.com/dRGxbH ) – user463035818
@POTEMKINDX已更新。顺便说一句,你没有创建一个实例。 – nikitablack