I would like to define an explicit specialization of the template function in the cpp file. Is it possible? To be more specific, I have the following code that compiles without errors:
class myclass
{
public:
myclass();
template<typename T> T Trigger(T rn);
private:
template<> int Trigger<int>(int rn)
{
int_do(rn);
}
template<> double Trigger<double>(double rn)
{
double_do(rn);
}
}
However, I, having the definitions in the header file, looks strange to me, so I would like to separate the definitions from the declarations, something like this:
class myclass
{
public:
myclass();
template<typename T> T Trigger(T rn);
private:
template<> int Trigger<int>(int rn);
template<> double Trigger<double>(double rn);
}
and
template<> int myclass::Trigger<int>(int rn)
{
int_do(rn);
}
template<> double myclass::Trigger<double>(double rn)
{
double_do(rn);
}
Is there any way to do this?
source
share