开发者

C++ error: cannot declare field to be of abstract type

This is the sit开发者_运维知识库uation:

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;   
};  

When I compile it gives the error message:

error: cannot declare field MyClass::b to be of abstract type because the following virtual functions are pure within Base:

Base::methodA()

Base::methodB()

How to solve this?

UPDATE It compiles now. I dont'know what I have changed


You code seems correct and perfect .

Your Base Class is Abstract so you can't create object of it , but you can definately declare pointer of it.

So you might have written Base b instead of Base *b ,please check it.


Your code snippets compiles fine on my computer. Are you sure that you are using Base* b, ie. a pointer type and not Base b?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜