Transferred from: http://bbs.csdn.net/topics/390082114
See the hidden and covered functions in the high-quality C + + code:
overriding refers to a subclass function overriding a base class function
Within different classes (in subclasses and parent classes, respectively).
Same name as the same parameter.
The base class must have the virtual keyword before the function name.
Hiding a function that refers to a derived class hides a function with the same name as the base class
If a derived class function has the same name as a base class function, but the arguments are different, the base class function is hidden regardless of whether there is a virtual modification before the base class function.
If the derived class function has the same name as the base class function, the parameters are the same, but the base class function is not virtual-modified before the base class function is hidden.
1 classBase2 {3 Public:4 Virtual voidFfloatx) {cout <<"base::f (float)"<< x <<Endl;}5 voidGfloatx) {cout <<"base::g (float)"<< x <<Endl;}6 voidHfloatx) {cout <<"base::h (float)"<< x <<Endl;}7 };8 9 classDerived: PublicBaseTen { One Public: A Virtual voidFfloatx) {cout <<"derived::f (float)"<< x <<Endl;} - voidGintx) {cout <<"derived::g (int)"<< x <<Endl;} - voidHfloatx) {cout <<"derived::h (float)"<< x <<Endl;} the};
The Derived::f (float x) function overrides the base class Base::f (float x) function. The child parent has the same name as the same parameter, and the parent class has the virtual keyword
The derived::g (int x) function hides the base class Base::g (float x) function. Different parameters with the same name, regardless of whether or not the virtual modification
The Derived::f (float x) function hides the base class Base::f (float x) function. Same name with same parameter, and base class has no virtulal decoration
Hiding and overwriting of C + + functions