【发布时间】:2009-10-27 10:30:07
【问题描述】:
情况是这样的:
class Base {
virtual void methodA() = 0;
virtual void methodB() = 0;
};
class Base_A : public Base {
void methodA();
void methodB();
};
class Base_B : public Base {
void methodA();
void methodB();
};
class MyClass {
private:
Base * b;
};
当我编译它给出错误信息:
error: cannot declare field MyClass::b to be of abstract type because the following virtual functions are pure within Base:
Base::methodA()
Base::methodB()
如何解决?
更新 它现在编译。我不知道我改变了什么
【问题讨论】:
-
真的是
Base * b;而不是Base b;吗? -
你的代码 sn-p 正确吗?它实际上编译正常并且是正确的。也许您的原始代码有“Base b”而不是“Base * b”。 'Base b' 会给出你得到的错误。
-
另外..不要忘记将 Base 析构函数设为虚拟。
-
“现在可以编译了。我不知道我改变了什么”——魔术!
标签: c++