小编ntx*_*ntx的帖子

MSVC中的虚拟继承错误

似乎我的问题是MSVC中的一个错误.我正在使用带有Service Pack 1的Visual Studio 2008,我的代码适用于GCC(在codepad.org上测试).

有关此错误的任何官方信息?任何想法如何解决它?VS2010中是否修复了该错误?所有的见解将不胜感激.

代码:

struct Base {
    Base(int i = 0) : i(i) {}
    virtual ~Base() {}
    virtual Base *clone() const = 0;

protected:
    int i;
};

struct A : virtual public Base {
    A() {}
    virtual A *clone() const = 0;
};

struct B : public A {
    B() {}
    B *clone() const { return new B(*this); }

    /// MSVC debugger shows that 'b' is for some reason missing the Base
    /// …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio

14
推荐指数
1
解决办法
1290
查看次数

标签 统计

c++ ×1

visual-studio ×1