Where is the “virtual” keyword necessary in a complex multiple inheritance hierarchy?

后端 未结 7 1690
死守一世寂寞
死守一世寂寞 2021-01-30 19:00

I understand the basics of C++ virtual inheritance. However, I\'m confused about where exactly I need to use the virtual keyword with a complex class hierarchy. F

7条回答
  •  无人及你
    2021-01-30 19:27

    You have to specify virtual inheritance when inheriting from any of A, B, C, and E classes (that are at the top of a diamond).

    class A;
    class B: virtual A;
    class C: virtual A;
    class D: virtual B;
    class E: virtual B, virtual C;
    class F: virtual C;
    class G:         D, virtual E;
    class H: virtual E,         F;
    class I:         G,         H;
    

提交回复
热议问题