Topic: Argument deduction for template conversion functions
Author: "Sanjay Pujare" <sanjayp@ddi.com>
Date: 1999/08/05 Raw View
Hi,
Consider,
struct A {
template <class T>
operator T* () { return 0; }
};
int main() {
A a;
int *p;
p = a;
}
Can the compiler use the conversion function template, deduce its argument
to be `int *' (i.e. T is `int *') for the assignment expression in main? The
C++ standard describes argument deduction only from function call arguments,
and not from return types or conversion function ids. But I wonder if I have
missed this anywhere in the standard.
What is the use of having a conversion function member template, if this
cannot be done? use only explicit template argument specification?
Sanjay
[ 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 ]
Author: Shiva <jshiva@bigfoot.com>
Date: 1999/08/06 Raw View
In article <7oaosk$dk$1@its.hooked.net>,
"Sanjay Pujare" <sanjayp@ddi.com> wrote:
>
> Hi,
>
> Consider,
>
> struct A {
> template <class T>
> operator T* () { return 0; }
> };
>
> int main() {
> A a;
> int *p;
>
> p = a;
> }
>
> Can the compiler use the conversion function template, deduce its
argument
> to be `int *' (i.e. T is `int *') for the assignment expression in
main? The
> C++ standard describes argument deduction only from function call
arguments,
> and not from return types or conversion function ids.
You are talking about about function overloading & not about template
argument deduction.
This is the relevant part of the Standard template arg deduction for
templated conversion functions.
[temp.deduct.conv] 14.8.2.3 Deducing conversion function template
arguments
1 Template argument deduction is done by comparing the return type of
the template conversion function
(call it P) with the type that is required as the result of the
conversion (call it A) as described in 14.8.2.4.
--
cheers,
Shiva
FAQ http://www.cerfnet.com/~mpcline/c++-faq-lite/
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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 ]