I got an explanation for you.

oasis (oasis)
class Base{
virtual void f(){}
virtual void f(int){}

class Derived : public Base{
void f(){}

int main()
Derived d;

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.
2001-7-18 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: A question about C++ polymorphism & inheritence

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习English