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.