The east of the constructor in C + + (i)

Source: Internet
Author: User

1. Each class defines how its objects are initialized, with special member functions that control the initialization of the object, a special function called a constructor.

2. The task of the constructor is to initialize the data members of the object. The constructor is executed whenever an object is created.

3. The constructor has the same name as the class name

4. The constructor does not have a return type

5. Constructor overloading, must differ on number of arguments or parameter types

6. Constructors cannot be declared as const [construct completes initialization process, object can actually get const property]

7. When a constructor is not defined, the compiler implicitly defines a default constructor that controls the default initialization process through the default constructor. The default constructor does not require any arguments

8. The compiler will generate a default constructor for us only if the class does not declare any constructors.

9. Once some other constructors are defined, the class does not have a default constructor unless we define a default constructor

10. When a class contains a member without a default constructor, the compiler cannot synthesize the default constructor for this class

11. Define the other constructors, you can define the default constructors in the form of =default

12. Constructors can assign an initial value to a data member by using the "initializer list"

The east of the constructor in C + + (i)

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.