类的成员函数是模板函数时的特例化:
class Test
{
public:
Test() {};
~Test() {};
template<typename T> void calc(T val);
/*{
cout<<val*2<<endl;
}*/
};
template<typename T>
void Test::calc(T val)
{
cout<<val*2<<endl;
}
template<>
void Test::calc(int val)
{
cout<<val*4<<endl;
}
int v1 = 2;
double v2 = 2.5;
Test t;
t.calc(v1);
t.calc(v2);