1. Overload, overlay and hide
1). Overload: "Overload" occurs when a member function has the following characteristics
A Same range (in same class)
B The function has the same name
C parameter types are different (implicit type conversions are not possible)
D Virtual keyword is optional
2). Overlay (also called "Inheritance"): Refers to a derived class function that overrides a base class function, characterized by:
A Different scopes (in base classes and derived classes, respectively)
B Same function name
C Parameters are the same
D The base class function must have the virtual keyword
3). Shadowing: Refers to functions of derived classes that mask a base class function with the same name as the following rules:
A If the function of the derived class has the same name as the function of the base class, but the arguments are different, the function of the base class will be hidden, regardless of the virtual keyword, to be confused with the overload.
B If the function of the derived class has the same name as the function of the base class, and the arguments are the same, but the base class function does not have the virtual keyword, the function of the base class is hidden (note that you are confused with overrides)
2. Look at the following example code:
#include <iostream>
Using Std::cout;
Using Std::endl;
Class Base
{
Public
virtual void F (float x) {cout << "base::f (float)" << x << Endl;}
void g (float x) {std::cout << "base::g (float)" << x << Std::endl;}
void h (float x) {std::cout << "base::h (float)" << x <<std::endl;}
};
Class Derived:public Base
{
Public
virtual void F (float x) {std::cout << "derived::f (float)" << x << Std::endl;}
void g (int x) {std::cout << "derived::g (int)" << x << Std::endl;}
void h (float x) {std::cout << "derived::h (float)" << x << Std::endl;}
};
void Main (void)
{
Derived D;
Base *PB = &d;
Derived *PD = &d;
Pb->f (3.14f);//derived::f (float) 3.14
Pd->f (3.14f);//derived::f (float) 3.14
Pb->g (3.14f);//base::g (float) 3.14
Pd->g (3.14f);//derived::g (int) 3
Pb->h (3.14f);//base:h (float) 3.14
Pd->h (3.14f);//derived::h (float) 3.14
}