0

简单的问题:这种层次结构会导致 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
};
4

1 回答 1

7

不。画图;所有基地都是独一无二的:

A
|
V
B   C
 \ /
  V
  D

“钻石问题”仅适用于由于多个重复的基类而导致的模棱两可的基类,例如,如果D要从A -> Band派生A -> C

No-diamond-problematic:                 Virtually-inherited diamond:

        A   A                                         A
        |   |                                       v/ \v
        B   C                                       B   C
         \ /                                         \ /
          V                                           V
          D                                           D
于 2012-01-11T17:56:33.840 回答