Overload & override & hide

Source: Internet
Author: User

Member functions are overloaded.(Overload)Features

(1) the same range (in the same class)
(2) functions with the same name
(3) Different Parameters
(4) virtual keywords are optional
Overwrite(Override)Indicates that the function of a derived class overwrites the base class function. The feature is 
(1) different scopes (located in the derived class and the base class respectively)
(2) functions with the same name
(3) Same Parameters
(4) basic functions must have virtual keywords.
"Hide"(Hide)The function of the derived class shields the base class functions with the same name. The rules are as follows: 
(1) If the function of the derived class has the same name as the function of the base class, but the parameter is different. In this case, functions of the base class will be hidden no matter whether there is any virtual keyword.
(2) If the function of the derived class has the same name and parameter as the function of the base class, but the base class function does not have the virtual keyword. In this case, the base class function is hidden.

In three cases:

1. Overload: view parameters

2. Hide: Call whatever you use

3. Overwrite: Call a derived class

 

Example:

Class base

{

Public:


Virtual void F (int x) {cout <"base: F (INT)" <X
<Endl ;}

Void g (int
X) {cout <"base: G (INT)" <x <Endl ;}

Void H (int
X) {cout <"base: H (INT)" <x <Endl;
}

};

Class derived: public Base

{

Public:

Void F (int
X) {cout <"derived: F (INT)" <x <Endl;
}

Void g (float
X) {cout <"derived: G (float)" <x <Endl;
}

Void
H (int x) {cout <"derived: H (INT)" <x <
Endl ;}

};

(1) The derived: F (INT) function overwrites base: F (INT ).

(2) The derived: G (INT) function hides the base: G (float) instead of the overload.

(3) The derived: H (INT) function hides base: H (INT) instead of overwrite.

 

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.