C + + constructor execution order __jquery

Source: Internet
Author: User

Tested in the following order:

First, the constructor of the static member is executed, and if the static member is declared in the class definition but not implemented, it is not constructed. It must be initialized before its constructor is executed.

The constructors of any virtual inheritance base class are constructed in the order in which they are inherited (not in the order in which the list is initialized)

Iii. constructors of any non-virtual inherited base class are constructed in the order in which they are inherited (not in the order in which the list is initialized)

The constructors of any member objects are constructed in the order in which they are declared

Five, class own constructors

The test procedure is as follows:[CPP]  View plain copy #include  <iostream>   #include  <string>   using  namespace std;     //abstract class a   class a   {   public :       a ()        {            cout<< "constructor for abstract Class A" <<endl;       }        //pure virtual function fun       virtual void fun1 ()   = 0;  };     //abstract class b   class b   {   public:        b ()        {            cout<< "constructor for abstract class B" <<endl;       }        //pure virtual function fun       virtual void fun2 ()  = 0;  };     //General c   class c   {   public:       c ()        {            cout<< "Class C constructor" <<endl;       }   };     //Common class d   class d   {   public:        d ()        {            cout<< "Class D constructor" <<endl;       }  };      //Common type c   class e   {   public:        e ()        {            cout<< "Class E constructor" <<endl;       }  };    &nbsp General class d   class f   {   public:       f ()         {           cout<< " Constructor for Class F "<<endl;       }  };     //Common class d    class g   {   public:       g ()         {           cout<< "Class G constructor" << endl;       }  };     /General class d   Class h    {   public:       h ()        {            cout<< "Constructor for Class H" <<endl;       }  };  //Common class d   class m   {   public:       m ()        {            cout<< "Class M constructor" <<endl;       }   };      Class test: public a,public b,virtual public  C,virtual public D,public E,public F   {   public:       test (): B (), A (), D (), C (), F (), E ()        {            cout<< "class Test constructor" <<endl;        }       void fun1 ()        {       }       void fun2 ()         {       }   private:       G g;  &nBsp     static H h;       static M m;   };      h test::h;      int main (int argc, char*  argv[])    {       Test test;        return EXIT_SUCCESS;  }   result:  class H constructor   (Static member class, and initialized)
Constructor for Class C (Virtual inheritance base class)
Constructor for Class D
Constructor for abstract Class A (non-virtual inheritance base class)
Constructors for abstract class B
Constructor for Class E
Constructor for Class F
Constructor for Class G (normal member object construction)
Constructor for class test (derived class own constructor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.