1. Static member was first constructed in accordance with the static member initialization sequence, which is not a class declaration order
2. The parent class constructor
3. Non-static members constructed in accordance with the class member declaration order, not the order of initializing the members comma
4. own constructor
Demo:
class TestA { public: Head(){ std::cout << "TestA()" << std::endl; } }; class TestB { public: TestB(int b) { std::cout << "TestB()" << std::endl; } }; class TestC { public: TestC(int c) { std::cout << "TestC()" << std::endl; } }; class TestD { public: TestD() { std::cout << "TestD()" << std::endl; } }; class TestE { public: Test() { std::cout << "TestE()" << std::endl; } }; class Father { public: Father() { std::cout << "Father()" << std::endl; } ~Father() { std::cout << "~Father()" << std::endl; } }; class SonA : public Father { public: Sounds (int num1, int num2) :m_C(num1) ,m_B(num2) { std :: cout << "SonA ()" << std :: endl; // First Father, Son and finally } ~ End () { std::cout << "~SonA()" << std::endl; } public: static TestD m_gD; m_gE static tests; private: TestA m_A; TestB m_B; TestC m_C; // member declaration order A, B, C, comma negligible initialization sequence }; Sona Test :: m_gE; TestD SonA :: m_gD; // static initialization sequence E, D int main () { end end (1, 2); }
Output:
Test() TestD() Father() Head() TestB() TestC() end ()