Class Base{public:base (int i) {cout << i;} ~base () {}};class base1:virtual public base{public:base1 (int i, int j=0): Base (j) {cout << i;} ~base1 () {}};class base2:virtual public base{public:base2 (int i, int j=0): Base (j) {cout << i;} ~base2 () {}};class derived:public Base2, public base1{public:derived (int a, int b, int c, int d): mem1 (1), MEM2 (2), Base 1 (3), Base2 (4), Base (1) {cout << B;} Private:base2 mem2; Base1 mem1;}; int main (int argc, char **argv) {Derived OBJD (1, 2, 3, 4); GetChar (); return 0;}
- First, the constructors of any virtual base class are constructed in the order in which they are inherited;
- Second, the constructors of any non-virtual base class are constructed in the order in which they are inherited;
- Finally, the constructors of any member objects are called in the order in which they are declared;
C + + initialization order