I have a C++ class that is templatized like so:
template <typename Operator>
class MyClass;
Where Operator can also be templatized itself into:
template <typename Param1, typename Param2, typename Param3>
class MyOperator;
Now, when I try to write a templatized method for the class, MyClass, I get an error - this code:
template < template < typename Param1, typename Param2, typename Param3 > typename Operator >
void MyClass<Operator<Param1, Param2, Param3>>::FunctionName()
Produces the error: "undeclared identifier" for each of Param1, Param2, Param3 and Operator. Why would this be, since the typenames/classes are specified right above?
I know the example code doesn't make that much sense, but my ultimate goal is to partially specialize it to look something like:
template < template < typename Param1, typename Param2, typename Param3 > typename Operator >
void MyClass<Operator<Param1, "CustomParam", Param3>>::FunctionName()
So that if the second Param is "CustomParam", the function would execute a specific implementation. Would this work, even though I specify all the parameters as template parameters (since the parameter I want to specialize is the second parameter, but the first is not specialized)? Thanks!
Parameter names in template template parameter are just informative (as names for parameters in function pointer void (*f)(int a, int b)
(a
and b
cannot be used)), you should do:
template <template <typename, typename, typename> typename Operator,
typename Param1, typename Param2, typename Param3>
void MyClass<Operator<Param1, Param2, Param3>>::FunctionName() {/*...*/}
Notice that you cannot partial specialize method/function, you have to partial specialize the whole class.