Re: multiple inheritance
"Sushrut Sardeshmukh" <bestbrain@gmail.com> writes:
Can you please help me to understand why this code does not compile?
I expect foo() to be called from B as signature matches the call.
where as if i call ptr->foo(10) then C::foo(int i) should be called.
but it does not happen.
class A{};
class B
{
public:
void foo()
{
cout<<"foo B"<<endl;
}
};
class C
{
public:
void foo(int i)
{
cout<<"foo C "<<endl;
}
The declaration of the member function name foo hides all inherited
member functions of that name, unless you say otherwise:
using B::foo;
};
class D:public C, public B
{
};
int main(int argc, char * argv[])
{
D *ptr = new D();
ptr ->foo();
return 0;
}
error: request for member `foo' is ambiguous
error: candidates are: void B::foo()
error: void C::foo(int)
This error message is misleading.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]