tags:

views:

510

answers:

3

This is the situation:

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

+1  A: 

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?

Ferdinand Beyer
I'm guessing not, since the compiler error talks about an abstract type, not a pointer.
Jurily
@Jurily: Yes, Base is abstract. If you try to create a field of this type (`Base b`), the compiler will complain that one *cannot declare field MyClass::b to be of abstract type*. Pointers to abstract types are not abstract, though, and the OP's example (`Base * p`) should work.
Ferdinand Beyer
+2  A: 

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.

Ashish
A: 

Solved, I don't know how but it works now

Derk