C
Chameleon
Can anyone explain me why the code below produce (with mingw-g++) the
following error message:
---------------------------------------------------------------
main10.cpp: In function `int main()':
main10.cpp:23: error: request for member `getZero' is ambiguous
main10.cpp:12: error: candidates are: virtual int B::getZero(int)
main10.cpp:6: error: virtual int A::getZero()
---------------------------------------------------------------
No! member getZero is not ambiguous at all because
int A::getZero()
is completelly different from
int B::getZero(int a)
Compiler can exactly decide what member to call when I say
c.getZero()
it is A::getZero() because B::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 B
{
public:
virtual int getZero(int a) { return a - a; }
};
class C : public A, public B {};
int main()
{
C c;
printf("%d", c.getZero());
return 0;
}
------------------------------------------------------
following error message:
---------------------------------------------------------------
main10.cpp: In function `int main()':
main10.cpp:23: error: request for member `getZero' is ambiguous
main10.cpp:12: error: candidates are: virtual int B::getZero(int)
main10.cpp:6: error: virtual int A::getZero()
---------------------------------------------------------------
No! member getZero is not ambiguous at all because
int A::getZero()
is completelly different from
int B::getZero(int a)
Compiler can exactly decide what member to call when I say
c.getZero()
it is A::getZero() because B::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 B
{
public:
virtual int getZero(int a) { return a - a; }
};
class C : public A, public B {};
int main()
{
C c;
printf("%d", c.getZero());
return 0;
}
------------------------------------------------------