我很难说出一个合适的头衔。
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;
^~~~~~~
为什么要在这里请求复制构造函数?当我摆脱虚拟继承(以及Base(int)
初始化列表中的Comp
调用)时,问题就消失了。
这是gcc version 6.2.1 20161124 (Debian 6.2.1-5)
。