I believe that the best answer is already given here : Why does an overridden function in the derived class hide other overloads of the base class?
But I am confused a little bit, specially with the statement :
In order to override this behavior, an explicit action is required from the user: originally a redeclaration of inherited method(s) (currently deprecated), now an explicit use of using-declaration.
Suppose I have the following program :
#include <iostream>
using namespace std;
class Base
{
public:
int f(int i)
{
cout << "f(int): ";
return i+3;
}
};
class Derived : public Base
{
public:
double f(double d)
{
cout << "f(double): ";
return d+3.3;
}
};
int main()
{
Derived* dp = new Derived;
cout << dp->f(3) << '\n';
cout << dp->f(3.3) << '\n';
delete dp;
return 0;
}
I have two questions :
Can I assume, w.r.t derived class object, the
int f(int i)
function does not exist at all. This is not inherited because of name hiding.If I have to use this function in Derived class, I have to define it again in derived class?