Given a program as simple as
class A{void func();}
class B:public A{void func();}
class C:public B,A{void func();}
// call it
C p;
p.func();
How can a compiler determine which function is called ? Thank you.
Printable View
Given a program as simple as
class A{void func();}
class B:public A{void func();}
class C:public B,A{void func();}
// call it
C p;
p.func();
How can a compiler determine which function is called ? Thank you.
The most-derived class (C)'s function will be used in this case.
If C didn't have a func(), then B's would be used.
If C did have a func() but it had a different parameter list, then by default a compile error would result, but a "using B::func" statement in the class definition would allow B's func() to be used.
Besides, if your base class is virtual, it will use the virtual class first before checking itself.