Template Overloading

Hi there,

I'm not sure the above is the correct term but is there anyway to overload a template class?

For example I want to do the below but it doesn't seem to like it...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <typename T> class MyClass
{
     // etc...
};

template <typename T, typename T2> class MyClass
{
     // etc...
};

template <typename T1, typename T2, typename T3> class MyClass
{
     // etc...
};

I basically need a way to have the same class but allow it to take a variable amount of arguments and types. Is this possible at all? Is it easy to implement?

Thank you for any help that is offered - it is always appreciated.

Regards,

Phil.
You can't have variadic templates with current C++ but it's planned to be available on the next standards of the language.
http://en.wikipedia.org/wiki/C%2B%2B0x#Variadic_templates
You can however have default values for template parameters and specialize your class
http://www.cplusplus.com/doc/tutorial/templates/
Thanks for the reply - the links were a great help.

Regards,

Phil.
something like this?

1
2
3
4
5
6
template <typename T1, typename T2 = int, typename T3 = float> class MyClass
{
     // etc...
};

Topic archived. No new replies allowed.