Example 1;
This is an illegal declaration - you cannot declare the template parameters more than once
1 2 3 4 5 6
template <typename T>
template <typename U>
class MyClass
{
};
If you have 2 template parameters for the class, then:
1 2 3 4 5
template <typename T, typename U>
class MyClass
{
};
Example 2: A template function in a template class
1 2 3 4 5 6 7 8 9 10 11 12
//declaration
template <typename T>
class MyClass
{
template <typename U>
U some_func(U param);
};
//definition
template <typename T>
template <typename U>
U MyClass<T>::some_func(U param) {return param *2;}
Note when doing the definition, you have to get the template lines the right way around - this would be wrong:
1 2 3 4 5 6 7 8 9 10 11 12
template <typename T>
class MyClass
{
template <typename U>
U some_func(U param);
};
//Error - template parameters are not in the right order here
template <typename U>
template <typename T>
U MyClass<T>::some_func(U param) {return param *2;}