Conditions for the C + + compiler to synthesize a default constructor (the same as the synthetic default copy constructor) __jquery

Source: Internet
Author: User

When a user does not define a constructor for a class, the compiler does not have a default constructor for each class, and only synthesizes the default constructor when the compiler requires it. The compiler synthesizes the default constructors just to meet the compiler's needs, not to the programmer's needs (for example, the initialization of a member variable requires a programmer to define a constructor). 1, the object contains the object with the default constructor

Class a{public
:
	A ();
}
Class b{public
:
	a A;
}
In the group B requires the compiler to synthesize the default constructor to invoke A's default constructor to define (does not help the programmer initialize) b own member variables, and built-in type variables are not required.

2, the parent class with a default constructor

Class a{public
:
	A ();
}
Class B:public A
{
...
}
In an inheritance relationship, with compositing, the compiler needs to synthesize the default constructor class for B to call A's default constructor.

3, with a virtual function of the class

Class with a virtual function, the compiler synthesizes a virtual table that holds a virtual function pointer as needed. 4, virtual inheritance of the class

Related Article

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.