Topic: template casting operators
Author: Adi Shavit <adish@cs.huji.ac.il>
Date: 1997/04/15 Raw View
Hi,
I'm working on a template library for Image processing, and I'd like to
cast from one template instance to another using the casting operator .
That is, is it possible to cast from Test<int> to Test<float>
automaticly,
from within the template, without explicitly specifing the type?
(Of course assumuing that such automatic casting exist, which in my case
is true).
Thanx, Adi
Note:
I tryed using (as someone suggested):
template<class T>
class Test
{
public:
Test() {}
...
template<class U>
operator Test<U>() { ...; return Test<U>(...); }
}
but it wouldn't compile on MSVC++ 4.0.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/04/15 Raw View
Adi Shavit <adish@cs.huji.ac.il> writes:
> I tryed using (as someone suggested):
>
>template<class T>
>class Test
>{
>public:
> Test() {}
> ...
> template<class U>
> operator Test<U>() { ...; return Test<U>(...); }
>}
>
>but it wouldn't compile on MSVC++ 4.0.
I'm pretty sure that template conversion operators such as this are
allowed by the C++ committee's draft working paper. However, member
templates are a pretty new feature and most compilers don't support
them yet.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]