C + + Subclass inherits a parent class constructor with a parameter what should I write __jquery

Source: Internet
Author: User

Reference: http://tieba.baidu.com/p/1167962877

one, the parent class does not write the constructor,

The constructor of a

subclass can be written in "any" form without regard to the constructor of the parent class.
For example: The parent class is a CA, the subclass is CB, no constructor is written in the parent class, the constructor is not written in a subclass, or the constructor can be written in the following ways:
CB () {};
CB (): CA () {};
CB (int a, int b) {};
CB (int a, int b): CA () {};
You can do this in any of several ways. That is, the constructor of the parent class is completely ignored.
Two, the parent class writes out only one parameterless constructor.
Subclasses can not write constructors, or they may be written in the following categories.
CB () {};
CB (): CA () {};
CB (int a, int b) {};
CB (int a, int b): CA () {}; The
is the same when the parent class writes out only one parameterless constructor or no write constructor effect.
Three, the parent class only writes out a parameter constructor
At this point, the subclass should write the constructor "standard", such as
CA (int a, int b) {};
CB (int A, int b): CA (a,b) {};
or:
CA (int a, int b) {};
CB (int A, int b, int c): CA (a,b) {};
Four, the parent class has more than one parameter constructor,
At this point, the subclass implements the constructor of a parent class at least.
Five, the parent class has more than one parameter function and one parameterless constructor.
At this point, a subclass can only implement a constructor of a parent class, regardless of whether the subclass implements a parameter constructor or an parameterless constructor.
It should be noted at this point that the parameterless constructor of the parent class can be ignored even if the subclass is written as CB () {} and is correct. Even written as CB (int a, int b) {};
Summary of the above can be summed up in C + + subclass inherits the parent class when the rule of the constructor is:
1, when the parent class has an explicitly written constructor, the child class minimum implementation of the parent class.
2, when the parent class does not explicitly write the constructor, the subclass can write the constructor without writing the constructor or the "free" function. A more general rule of

is summarized as follows: The constructor of a subclass is based on a constructor that satisfies the parent class at least.


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.