我正在閱讀有關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