Re: ambiguous overload?
Victor Bazarov wrote:
highegg wrote:
given the declarations
class A {};
template <class X, class T> void method (double u, T v);
template <class X> void method (double u, long v);
...
double u; long v;
Is the following call unambigous (w.r.t. C++ standard)?
method<A> (u, v);
[..]
Yes.
I meant to say it was ambiguous. If you know what part of the Draft
says the second is a better match, could you point to it, please?
From what I figure, the first template could be more specialised than
the second because it has two types defined, not just one. However, all
the examples given in the Standard have to do with A<T*> vs A<T> (which
makes the former more specialised) and not A<T,U> vs A<T>. My
understanding of what makes templates "more specialised" can be
incorrect, so I'd appreciated somebody's explanation.
> Since it can be either
method<A,long>(u, v); // 'X'==A, 'T' is deduced from 'v'
or
method<A>(u, v); // 'X'==A, single template argument
, the compiler can't decide which one you want. If you specify the type
explicitly, like this
method<A,long>(u, v);
the ambiguity goes away since it cannot be the second template.
V
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask