> On Fri, 03 Oct 2003 01:51:55 +0900, Marc Schellens
> <> wrote:
>
>
>>Just to make it sure:
>>
>>it is not possible in C++ to have a template specialization
>>for more than one type, right?
>
>
> Right.
>
>
>>ie. I have several template type parameters like
>>string, int, long, char, float, double, complex.
>>
>>The template for float and double is exactly the same,
>>the one for the integer types as well.
>>So I can make the default case for the integer types, but
>>I have to repeat the code for the floating type specialization, right?
>
>
> Well, there are lots of ways you could share the code rather than
> repeat it. Inheritence is one way. e.g.
>
> template <class T>
> class MyClassFloat
> {
> //...
> };
>
> template<>
> class MyClass<float>: public FloatImpl<float> {};
> template<>
> class MyClass<double>: public FloatImpl<double> {};
>
> Another way is to use indirection to the implementation through
> traits, and bind float and double to the same traits.
>
> Tom
Thanks Tom,
but I was not specific enough, sorry:
I meant a member function specialization.
Any suggestions for that?
thanks,
marc
|