C++: Diamond concerns

102 views Asked by At

Simple question: Will this hierarchy cause a DP?

//Abstract base class
class A {
    //Implement pure virtual methods with a default definition.
    //Pure virtual methods are still declared pure virtual.
};

//Abstract derived class
class B : public A {
    //Define pure virtual methods with a default definition.
    //Pure virtual methods are still declared pure virtual.
};

//Abstract base class
class C {
    //Define pure virtual methods with a default definition.
    //Pure virtual methods are still declared pure virtual.
};

//Concrete class
class D : public B, public C {
    //Implement all methods from D, B, and C
};
1

There are 1 answers

0
Kerrek SB On BEST ANSWER

No. Draw the picture; all bases are unique:

A
|
V
B   C
 \ /
  V
  D

The "diamond problem" only pertains to ambiguous base classes due to multiple repeated bases, e.g. if D were to derive from both A -> B and A -> C:

No-diamond-problematic:                 Virtually-inherited diamond:

        A   A                                         A
        |   |                                       v/ \v
        B   C                                       B   C
         \ /                                         \ /
          V                                           V
          D                                           D