Home > Back-end >  Multiple inheritance in virtual inheritance, how do you write a constructor? Why is that?
Multiple inheritance in virtual inheritance, how do you write a constructor? Why is that?

Time:10-08

Are different two programs in the constructor of the class D, who can explain why appear such result?
Procedure 1

The results


Why a is initialized to 1 of class D object obj, rather than constructor in the class B default constructor in 2 or class D the default of 100?

Program 2

The results

CodePudding user response:

Virtual inheritance, there is only one base class A, not B or C, so you need to function in the construction of the D initialization list, specify A constructor,

CodePudding user response:

  • Related