It is irrelevant to the initialization list order of the derived class constructor, in the following order:
1. base class Constructor (in the order of inheritance)
2. Sub-object constructor (in the declared order of the Class)
3. self-built constructor of the derived class
Structure analysis:
Opposite to construction
The test procedure is as follows:
# Include <iostream>
Using namespace STD;
Class
{
Public:
A () {cout <"A" <Endl ;}
~ A () {cout <"~ A "<Endl ;}
};
Class B
{
Public:
B () {cout <"B" <Endl ;}
~ B () {cout <"~ B "<Endl ;}
};
Class C
{
Public:
C () {cout <"C" <Endl ;}
~ C () {cout <"~ C "<Endl ;}
};
Class D
{
Public:
Int D;
D () {cout <"d1" <Endl ;}
D (int A): D (a) {cout <"D2" <Endl ;}
~ D () {cout <"~ D "<Endl ;}
};
Class E: Public B, public
{
Public:
D;
C;
E (): A (), C (), B (), D () {cout <"E" <Endl ;}
~ E () {cout <"~ E "<Endl ;}
};
Class F: Public E, public
{
Public:
C Cf;
D DF;
F (): A (), CF (), DF (5) {cout <"F" <Endl ;}
~ F () {cout <"~ F "<Endl ;}
};
Int main (INT argc, _ tchar * argv [])
{
F;
Return 0;
}
**************************************** **********************
The output is as follows:
B
A
D1
C
E
A
C
D2
F
~ F
~ D
~ C
~ A
~ E
~ C
~ D
~ A
~ B