C ++ default constructor

Source: Internet
Author: User

The default constructor is not provided.Displayed(IncludingNo ParametersAndDefault parametersIs used to create object constructor.

Constructor used for the following declaration

Stock stock1;

Note:

The compiler provides the default constructor only when no constructor is defined,

When we define constructors, we must provide Default constructors, such

Stock (const char * CO, int N, double pr); this is a constructor, but it is not the default constructor. If we do not provide the default constructor, this will cause an error.

There are two constructor types to complete:

1. Function overload. constructor without Parameters

Stock (){}

2. provide default values for all parameters of an existing constructor.

Stock (const char * CO = "error", int n = 0, double pr = 0.0 );

BecauseOnly one default constructor can be created., SoThe above two Default constructors cannot be used at the same time

After you create a default constructor using any of the above methods, you can declare the object variables without initializing them:

Do not use the default constructor for implicit call ();

Stock stock1; // call the default constructor implicitly

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.