Pure virtual methods cannot be inherit?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rafael Justo
    New Member
    • Mar 2007
    • 9

    Pure virtual methods cannot be inherit?

    Check the following code example:

    Code:
    ///////////////////////
    
    class A
    {
    public:
      int a;
    };
    
    ///////////////////////
    
    class B : public A {};
    
    ///////////////////////
    
    class C
    {
    public:
      virtual void c(A *a) = 0;
    };
    
    ///////////////////////
    
    class D : public C
    {
      void c(B *b) {}
    };
    
    ///////////////////////
    
    int main()
    {
      D d;
      return 0;
    }
    The compiler gives me the following error:
    cannot declare variable ‘d’ to be of abstract type ‘D’ because the following virtual functions are pure within ‘D’: virtual void C::c(A*)

    I don't understand why the compiler doesn't accept it. The object used in the parameter is an extension of the original one used in the abstract class.

    Any ideas?

    Best regards,
    Rafael
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    They can be inherited, but the argument list must be the same - the fact that B is inherited from A doesn't matter.

    Comment

    Working...