Links: https://www.nowcoder.com/questionTerminal/266d3a6d4f1b436aabf1eff3156fed95
Source: Niu Ke Net
title :
The overload, overwrite, and hide differences of class member functions are described correctly.
A, overwrite refers to the same name in the same class, the parameters are different
B, overloading refers to a derived class function overriding a base class function, the same function, the same parameters, the base class function must have the virtual keyword
C, the derived class function is the same as the base class function, but with different parameters, the parent class function is "hidden"
D, the function name is the same, the parameters are the same, the base class without the virtual keyword function of the derived class will "hide" the parent class function
Answer :
Cd
parsing :
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. Overwrite refers to a derived class function overriding a base class function, characterized by:
(1) different ranges (in the derived and base classes, respectively);
(2) The function has the same name;
(3) the same parameters;
(4) The base class function must have the 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).
Overloading, overwriting, and hiding of "non-original" C + + class member functions