Home > Back-end >  Of new want to consult the order of virtual inheritance structure of c
Of new want to consult the order of virtual inheritance structure of c

Time:01-09

# include
using namespace std;
Class A {
Public:
(A) {
Cout & lt; <"A Done! \ n ";
}
};
Class E: public A {
Public:
(E)
{
Cout & lt; <"E Done! \ n ";
}
};
Class B: virtual public A {
Public:
(B) {
Cout & lt; <"B Done! \ n ";
}
};
Class C: virtual public A {
Public:
(C) {
Cout & lt; <"C Done! \ n ";
}
};
Class D: public E, public B, public C {
Public:
(D)
{
Cout & lt; <"D Done! \ n ";
}
};

Int main () {
D D;
return 0;
}
This is the code

This is the results
What why construction order please? Small white just learning A little don't understand why will construct A twice first

CodePudding user response:

E is not virtual inheritance, so it will be invoked once A constructor, BC virtual inheritance, two calls one time
  • Related