C ++ constructor Call Sequence

Source: Internet
Author: User

1. Create an object of the derived class. The constructors of the base class are preferentially called (or the member classes in the derived class );

2. If a Member class exists in the class, the constructor of the member class is called first;

3. If a base class constructor has multiple base classes, the calling sequence of the constructor appears in a class derived table.
The sequence instead of the sequence in the member initialization table;

4. Member class object constructor if there are multiple Member class objects, the calling sequence of the constructor is that the object is in the class.
The declared order rather than the order in which they appear in the member initialization table;

5. derived class Constructor
As a general rule, the derived class constructor should not directly assign values to a base class data member, but pass values.
Give the appropriate base class constructor. Otherwise, the implementation of the two classes will become more difficult to be tightly coupled (tightly coupled ).
Modify or extend the implementation of the base class correctly. (The responsibility of the base class designer is to provide a set of appropriate base class 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.