What would be the difference between the next two declarations:
template<class T, class functor>
methodReturnType className::methodName(functor f)
and:
template<class T>
template<class functor>
methodReturnType className::methodName(functor f)
I was trying to write a method that would work with a functor arg. The second declaration allowed me to avoid to declare the whole class as a template of both T and functor. I wanted to have a template class className of only one parameter T, but inside that class, a method had another parameter functor, while not declaring the whole class as a template of two parameters. It worked, but I didn't thoroughly understand it.
Second variant is right for your case by language rules.
n3376 14.5.2/1
A member template of a class template that is defined outside of its class template definition shall be specified with the template-parameters of the class template followed by the template-parameters of the member template.
[ Example:
template<class T> struct string { template<class T2> int compare(const T2&); template<class T2> string(const string<T2>& s) { /∗ ... ∗/ } }; template<class T> template<class T2> int string<T>::compare(const T2& s) { }
— end example ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With