This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Is this really an ambiguous reference?
- From: "Ben Cronin" <beren77 at lycos dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 07 Aug 2003 05:24:07 -0400
- Subject: Is this really an ambiguous reference?
- Organization: Lycos Mail (http://www.mail.lycos.com:80)
- Reply-to: beren77 at lycos dot com
I'm curious why gcc reports the call to print() below as an ambiguous reference. Is this ambiguous according to the C++ standard? It seems like gcc would be able to figure out that the code should call B::print(T&) this a.t's type is known. Here's the code:
--------
#include <cstdio>
using namespace std;
struct B
{
struct T { } t;
void print(T&) { printf("B\n"); }
};
struct C
{
struct S { } s;
void print(S&) { printf("C\n"); }
};
struct A : public B, public C
{
};
int main(int argc, char** argv)
{
A a;
a.print(a.t);
return 0;
}
--------
GCC prints the error:
test.cpp: In function `int main(int, char**)':
test.cpp:22: request for member `print' is ambiguous
test.cpp:12: candidates are: void C::print(C::S&)
test.cpp:7: void B::print(B::T&)
Also, it was pointed out to me that adding "using A::print; using B::print;" in the definition of A unambiguates the reference. But why is that necessary?
Thanks.
____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005