I’m code reviewing a colleagues code and found this:
Header file:
template<class T>
class MyClass
{
void Execute();
}
Cpp file:
void MyClass<int>::Execute()
{
// something
}
void MyClass<string>::Execute()
{
// something else
}
The code is specializing the function, but without using template specialization syntax. I guess it’s working ok, but is it valid?
This is the old syntax for explicit specialization. But I’m surprised that you are using a compiler which still accept it (g++ stopped around 4.0). To be conforming you need to prefix the specialization with
template <>.