构造函数尝试调用复制构造函数,虚拟继承
Constructor tries to call copy constructor, virtual inheritance
我很难表达一个合适的标题。
struct Base
{
Base(int) {}
virtual ~Base()=default;
};
struct Derived: virtual public Base
{
Derived(float, int): Base{1} {}
Derived(Derived const&)=delete;
~Derived()=default;
};
struct Comp: private Derived
{
Comp(): Base{1}, Derived{1.0f, 1} {}
};
这给出了编译器错误:
x.cc: In constructor ‘Comp::Comp()’:
x.cc:16:34: error: use of deleted function ‘Derived::Derived(const Derived&)’
Comp(): Base{1}, Derived{1.0f, 1} {}
^
x.cc:10:2: note: declared here
Derived(Derived const&)=delete;
^~~~~~~
为什么在这里需要复制构造函数?当我摆脱虚拟继承时,问题消失了(因此Comp
的初始值设定项列表中的Base(int)
调用)。
这是在gcc version 6.2.1 20161124 (Debian 6.2.1-5)
.
这似乎是 GCC 中的一个错误。Clang和GCC 7都接受代码。
相关文章:
- 虚拟继承基构造函数消除
- 使用回调函数从构造函数调用虚拟/派生方法的替代方法?
- 我是否需要在虚拟继承类的构造函数中初始化基类以解决菱形继承问题?
- 为什么构造函数的虚拟函数调用有时有效,但其他调用却无效
- 使用范围解析运算符时,在构造函数中调用虚拟方法是否安全?
- 虚拟继承构造函数的组装
- C++ 虚拟继承和构造函数
- 为什么不调用虚拟基非默认构造函数,除非大多数派生基显式调用它们?
- 抽象类和虚拟构造函数的替代方案
- C 构造函数订单,而虚拟继承
- (为什么)纯虚拟派生类中是否需要虚拟基类构造函数调用?
- 使用具有虚拟多重继承的基构造函数
- 在没有限定的情况下从 T 构造函数调用类 T 的纯虚拟实现?
- C 语言设计:孩子称呼所有虚拟祖先构造函数
- 虚拟继承和默认构造函数
- 具有虚拟多重继承的构造函数定义
- 构造函数尝试调用复制构造函数,虚拟继承
- 构造函数C++中的虚拟方法
- 模拟虚拟方法的构造函数
- 在C 中的多级虚拟继承中受保护的构造函数