You probably know that local variable hides global variable name regardless of types
1 | int x; // global variable |
Inheritance function naming share the similar mechanism.
1 | class Base { |
Regardless of virtual
, pure-virtual
or non-virtual
function, as soon as you define a function named mf3
in derived class, it hides all functions named mf3
in base class.
1 | Derived d; |
In public inheritance, you most likely want to inherit all public functions in base class, the way to do it to use using
keyword to bring all function with certain name to the scope of derived class.
1 | class Derived: public Base { |
This way, all mf3
functions in base class will be brought to scope in Derived
.
1 | Derived d; |
In private inheritance, you might not want to bring all functions with certain name to scope of derived class, the way you do it is simply forward the function to cal base class version.
1 | class Base { |