 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
James Dennett Guest
|
Posted: Thu Aug 14, 2003 10:32 pm Post subject: Re: Ambiguous call or compiler bug? |
|
|
Richard Corden wrote:
| Quote: | CODE
template <typename T
int bar (T t1, T t2);
template
int bar (T t, int); // more specialized?
void func ()
{
bar (10, 20);
}
/CODE
It seems to me that the second overload of bar is 'more specialized'
than the first, yet most of my compilers say its ambiguous?
|
It appears to me that neither is more specialized than the
other: there are calls to each that can't be made to the
other.
template
is more specialized that either, of course.
-- James.
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
John Potter Guest
|
Posted: Fri Aug 15, 2003 1:29 am Post subject: Re: Ambiguous call or compiler bug? |
|
|
On Thu, 14 Aug 2003 18:56:39 +0000 (UTC), [email]wolof (AT) freemail (DOT) hu[/email] ("White
Wolf") wrote:
| Quote: | Richard Corden wrote:
CODE
template
int bar (T t1, T t2);
template
int bar (T t, int); // more specialized?
void func ()
{
bar (10, 20);
}
/CODE
It seems to me that the second overload of bar is 'more specialized'
than the first, yet most of my compilers say its ambiguous?
Any thoughts?
Just one: it is overloaded, not specialized.
|
Correct. The question is which if either overload is more
specialized. See 14.5.5.2.
| Quote: | Function templates (AFAIU) cannot be specialized.
|
They can, but they may not be partially specialized. Also, each
instantiation is a specialization. Hard to follow the words.
Getting back to the original question, I will attempt an answer to
see if I understand 14.5.5.2.
We create a type, say Q. Using that for T in the first version gives
a call of bar(Q, Q). Argument deduction in the second version fails
with that call giving the first is not more specialized than the second.
Using that for T in the second gives bar(Q, int). Argument deduction in
the first version fails with that call giving the second is not more
specialized than the first. Since neither overload is more specialized
than the other, the call is ambiguous.
John
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
chris Guest
|
Posted: Sun Aug 17, 2003 6:58 pm Post subject: Re: Ambiguous call or compiler bug? |
|
|
Richard Corden wrote:
| Quote: | CODE
template
int bar (T t1, T t2);
template
int bar (T t, int); // more specialized?
|
The second isn't a specialized version of the first one, as in the first
one you require both of the types to be the same
| Quote: |
void func ()
{
bar (10, 20);
}
/CODE
It seems to me that the second overload of bar is 'more specialized'
than the first, yet most of my compilers say its ambiguous?
Any thoughts?
Kind Regards,
Richard
|
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|