class Base{
public:
virtual void f(){}
virtual void f(int){}
};
class Derived : public Base{
public:
void f(){}
};
int main()
{
Derived d;
d.f(1);
}
This code has two names Base::f and Derived::f, Base::f is overloaded. When
the compiler sees d.f(1) it first looks up the name and finds Derived::f. It
doesn't look any further because all its doing at the moment is looking up
the name f. Having found Derived::f is then sees if it can match arguments
(i.e. do overload resolution). In this case it finds it can't so it gives up
with an error message.
It was designed for this way for reasons of simplicity, the rules for name
lookup and overload resolution are complicated enough already. Seperating
these rules makes things simpler.
the answer from a c++ expert on the internet.
public:
virtual void f(){}
virtual void f(int){}
};
class Derived : public Base{
public:
void f(){}
};
int main()
{
Derived d;
d.f(1);
}
This code has two names Base::f and Derived::f, Base::f is overloaded. When
the compiler sees d.f(1) it first looks up the name and finds Derived::f. It
doesn't look any further because all its doing at the moment is looking up
the name f. Having found Derived::f is then sees if it can match arguments
(i.e. do overload resolution). In this case it finds it can't so it gives up
with an error message.
It was designed for this way for reasons of simplicity, the rules for name
lookup and overload resolution are complicated enough already. Seperating
these rules makes things simpler.
the answer from a c++ expert on the internet.