"Chameleon" <cham_gss@hotmail.comwrote in message
news:enjbla$pph$1@volcano1.grnet.gr
Quote:
Simpler paradigm with no Multiple Inheritance
>
Quote:
>Can anyone explain me why the code below produce (with mingw-g++) the
>following error message:
>---------------------------------------------------------------
main10a.cpp: In function `int main()':
main10a.cpp:19: error: no matching function for call to `C::getZero()'
main10a.cpp:12: note: candidates are: virtual int C::getZero(int)
Quote:
>---------------------------------------------------------------
>>
>No! member getZero is not ambiguous at all because
>int A::getZero()
>is completelly different from
>int C::getZero(int a)
>>
>Compiler can exactly decide what member to call when I say
>c.getZero()
>it is A::getZero() because C::getZero(int) has parameters.
>>
>Is this a compiler (gcc) or a language limitation?
>>
>Thanks!
>>
>-----------------------------------------------------
#include <cstdio>
>
class A
{
public:
virtual int getZero() { return 0; }
};
>
class C : public A
{
public:
virtual int getZero(int a) { return a-a; }
};
>
int main()
{
C c;
printf("%d", c.getZero());
return 0;
}
Quote:
>------------------------------------------------------
As Yan points out regarding the second example, getZero in C hides getZero
in A. They are not treated as overloads.
You can get them treated as overloads, however, by adding
using A::getZero;
to the declaration of C.
As for your first multiple inheritance example, once again, overloads are
not made across classes. As Stroustrup points out: "When combining
essentially unrelated classes...similarity in naming typically does not
indicate a common purpose."
Because overloading is not done across classes, C++ just looks at the names
and hence reports ambiguity.
You can resolve the problem in the same way by bringing both functions into
a common scope. Change class C to:
class C : public A, public B
{
public:
using A::getZero;
using B::getZero;
};
--
John Carson