构造函数尝试调用复制构造函数,虚拟继承

时间:2017-01-12 19:47:33

标签: c++ constructor 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;
  ^~~~~~~

为什么要在这里请求复制构造函数?当我摆脱虚拟继承(以及Base(int)初始化列表中的Comp调用)时,问题就消失了。

这是gcc version 6.2.1 20161124 (Debian 6.2.1-5)

1 个答案:

答案 0 :(得分:1)

这似乎是海湾合作委员会的一个错误。 Clang和GCC 7 accept the code