Is this really an ambiguous reference?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux