Inheritance from two abstract classes

I have a problem that I have not tested / compiled or wondered if this is possible, and if it's a bad design?

My problem:

I want to have an abstract base class A and an abstract derived class B.

I understand that if possible, I will have several pure virtual member functions in each class, and I will not be able to initialize these objects, but this is set for abstract classes.

In my project, I will have another derived class C, which I would then initialize - class C would be derived from class B.

I would have something like this

class C
  ^
  |
abstract class B
  ^
  |
abstract base class A

My question is:

Is this possible in the first place? I would suspect so, but not declaring pure virtual functions in in class B can be problematic?

ex

class A {
  public:
    virtual void test()=0;
 };

class B: public A {
  public:
   virtual void test()=0;
   virtual void anotherTest()=0;
 };

Is it good?

++? A, .

+3
1

, , , .

stefanos-imac:dftb borini$ more test.cpp 
#include <iostream>
class A {
public:
    A(void) { std::cout << "A" << std::endl; } 

    virtual void method1() = 0;
};

class B : public A {
public:
    B(void) : A() { std::cout << "B" << std::endl; }

    virtual void method2() = 0;
};

class C : public B {
public:
    C(void) : B() { std::cout << "C" << std::endl; }

    virtual void method1() { std::cout << "method1" << std::endl; }
    virtual void method2() {std::cout << "method2" << std::endl; }
};

int main() {
    C c;
    c.method1();
    c.method2();
}
stefanos-imac:dftb borini$ ./a.out 
A
B
C
method1
method2

, , ++.

+2

All Articles