Why does virtual inheritance need to be specified in the middle of a diamond hierarchy?

前端 未结 5 2407
醉梦人生
醉梦人生 2021-02-20 06:24

I have diamond hierarchy of classes:

    A
  /   \\
 B     C
  \\   /
    D

To avoid two copies of A in D, we need to use virtual inheritance a

5条回答
  •  粉色の甜心
    2021-02-20 06:52

    In addition to templatetypedef answer, it may be pointed out that you also may wrap A into

    class AVirt:virtual public A{}; 
    

    and inherit other classes from it. You wil not need to mark explicitly other inheriances as virtual in this case

提交回复
热议问题