Construction of default constructor

Source: Internet
Author: User

There are four cases (1. member Class Object with default constructor; 2. base class with default constructor; 3. class with a virtual function; 4. A class with a virtual base class) causes "the compiler must synthesize a default constructor for a class without a declared constructor ". C ++ stardand calls those compositions implicit nontrivial Default constructors. The constructor can only meet the requirements of the compiler (rather Program . The task can be completed by calling the default constructor of the member object or base class, or initializing the virtual function or virtual base class mechanism of each object. As there are no such four cases and no constructor class is declared, we say they have implicit trivial Default constructors which will not actually be merged.
In the merged default constructor, only base class subobjects and member class objects will be initialized. All other nonstatic data member, such as integers, integer pointers, and integer arrays, are not initialized. These initialization operations may be required for the program, but this is not necessary for the compiler. If the program needs a default constructor that "sets a pointer to 0", the provider should be a programmer.
C ++ beginners generally have two common misunderstandings:
1. If no default constructor is defined for any class, a constructor is merged.
2. The default constructor synthesized by the compiler will explicitly set the default value for each data member in the class"

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.