function overloading/shadowing/hidden

Overload, shade, hide

Function overloading: (only in a class, without inheriting the function of the parent class)

Indicates that in the same class, the function name is the same, but the parameters are different, which is called function overloading

 

Function shadowing: (the base class pointer points to the derived class, in the case of calling)

Function shadowing means that the subclass overrides the function of the parent class. The requirements for overriding are that the function name is the same, the parameters are the same, and the parent class function must have the virtual keyword. If the parent class does not have the virtual keyword, it will not constitute shadowing (hidden )

 

Function hiding: (refers to hiding when a subclass object accesses member functions)

Hidden means that a subclass function shields its parent class function or variable of the same name. (As long as the function name is the same, it will be hidden)

If the parameters are the same, the parent class function cannot have the virtual keyword

If the parameters are not the same, the parent class function will be hidden

 

 

Only when the virtual function of the base class is rewritten can C++ polymorphism be reflected

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324490189&siteId=291194637