There is this code:
#include <iostream>
#include <string>
#include <typeinfo>
// template class
template <class U, class X, class T>
class Klasa{
public:
template <class Z>
void Method(){
}
};
// partial class specialization
template <class U>
class Klasa<U, int, U>
{
public:
// template method
template <class Z>
void Method(){
}
};
// error occurs for that!
template <class U>
template <>
void Klasa<U, int, U>::Method<int>(){
}
int main()
{
Klasa<float, int, float> object;
object.Method<float>();
return 0;
}
Compilation error:
error: invalid explicit specialization before ‘>’ token
error: enclosing class templates are not explicitly specialized
error: template-id ‘Method<int>’ for ‘void Klasa<U, int, U>::Method()’ does not match any template declaration
I try to do specialization for method
void Klasa<U, int, U>::Method<int>
, however compiler doesn't accept it. How to write specialization for this method?