C + + constructor __jquery

Source: Internet
Author: User

Constructor: Invoked when an object is constructed (display invocation and implicit invocation), only when the object is constructed, the corresponding construction method is selected according to the parameter type and number of the new object, and the method is called when there are no parameters, and the corresponding parametric construction method is called when there are parameters. The parameters of the constructor are typically used to initialize the data members of the class
Features and functions of constructors:

1. Constructors must be named exactly the same as the class name.

2. The function of a constructor is primarily used to define the state of initialization when the object of a class is created. It has no return value, nor can it be decorated with void.

3. Constructors cannot be called directly, and must be invoked automatically by the new operator when an object is created.

4. When a class definition is defined, a constructor is usually default, and this default constructor takes no arguments. When you customize the Include parameter constructor, the default constructor will need to be written manually ... (the default constructor is parameter-free, and the constructor you define can take parameters)

Show Call constructor


The stock food = the stock (14,250,65);
Function: The stock class object food is created, and the class member data is initialized by invoking its own defined stock class constructor.

Implicit call constructor Stock food (14,250,65);
Function: The stock class object food is created, and the class member data is initialized by invoking its own defined stock class constructor. The results of the two invocation methods are the same, but the second method is more compact.

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.