Topic: Ambiguous call: is the compiler right or me?


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/06/20
Raw View
[ Discution moved from comp.lang.c++.moderated to comp.std.c++ ]

<jkanze@otelo.ibmmail.com> writes:

> In article <6euqiq$8rv@netlab.cs.rpi.edu>,
>   bonnardv@pratique.fr wrote:
> >
> > <daasb@rwg.de> writes:
> >
> > > When I try the following, my compiler complains about
> > > an ambigous call. Is he behind the standard or am I?
> >
> > This seems perfectly unambiguous to me. Only one function
> > can be called, so the rules to know which call is prefered
> > don't even have to be applied.
>
> I don't think it gets that far.  Overload resolution only works within
> a given scope; before it can be applied, the compiler must choose that
> scope.  I'm not 100% sure, but I believe that this choice is made
> uniquely on the name itself, without looking at the arguments or
> parameter lists.

And you are wrong in general, but right in this case.

Compare:

struct A
{
   void foo (const AParam&);
};

struct B
{
   void foo (const BParam&);
};

struct C
{
   void foo (const CParam&);
};

struct D : public A, public B, public C
{
    void bar ()
    {
        foo (CParam()); // (1) ambiguous
    }
};

and

namespace A
{
   void foo (const AParam&);
};

namespace B
{
   void foo (const BParam&);
};

namespace C
{
   void foo (const CParam&);
};

namespace ABC {
    using namespace A;
    using namespace B;
    using namespace C;

    void bar ()
    {
        ABC::foo (CParam()); // (2) ok
    }
}

Can some expert tell me what's the rationnal behind allowing
(2) but not (1) ?

[ FDIS 3.4.3.2 and 10.2 apply ]

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]