Ambigulty while calling overloaded operator
Here is the sample code:
struct A
{
virtual int operator & ( A & ) { return 0; }
};
struct B : public A {};
struct C : public A {};
struct D : public C, public B {};
int main()
{
D d;
std::cout << &d << std::endl;
return 0;
}
It perfectly works in VS 2008, but GCC fails to compile it:
../src/TestCast.cpp: In function 'int main()':
../src/TestCast.cpp:26:16: error: request for member 'operator&' is ambiguous
../src/TestCast.cpp:15:14: error: candidates are: virtual int
A::operator&(A&)
../src/TestCast.cpp:15:14: error: virtual int
A::operator&(A&)
make: *** [src/TestCast.o] Error 1
As far as I see, it looks for operator& overload by name, not by
signature, so it find ambiguous overload and produces an error.
The question is: is it correct by Standard? If not, which paragraph
describes it? Is there any way to make GCC accept this code (I mean,
lookup by signature, not by name).
BTW, I know, how to fix this code. I just want to know, WHY an error appears.
No comments:
Post a Comment