#include <iostream>classA { Public: voidfunc () {std::cout<<"Hello"<<Std::endl; } voidFuncintk) {}};classD | PublicA { Public: usingA::func;//Try this one out, hehe. voidFuncinti) {}};intMain () {b b; B.func ();//Compile error This sentence tells you not to accept 0 parameters.}
What is the difference between overloading, overriding, and hiding a class member function?
Answer:
A. Features that are overloaded with member functions:
(1) The same range (in the same class);
(2) The function has the same name;
(3) different parameters;
(4) The virtual keyword is optional.
b. Overrides refer to a derived class function that overrides a base class function, characterized by:
(2) functions have the same name; &NBSP;
(4) The base class function must have a virtual keyword.
C. " Hide refers to a function of a derived class that masks a base class function with the same name as the following rule:
(1) If the function of the derived class has the same name as the function of the base class, but the parameters are different. At this point, the function of the base class is hidden, regardless of the virtual keyword (Note that it is not confused with overloading).
(2) If the function of the derived class has the same name as the function of the base class, and the parameters are the same, the base class function does not have the virtual keyword. At this point, the function of the base class is hidden (be careful not to confuse the overlay)
When hidden, a function that does not see the parent class in the child class.
C + +: Overloading, overwriting, and hiding differences for class member functions?