函數(shù)模板
template <teypename 標(biāo)識符>
函數(shù)定義
定義一個絕對值的模板函數(shù)
template <typename T>
T abs(T x)
{
return x<0? -x : x ;
}
void main()
{ int n=-5;
float d=56.4;
cout<<abs(n)<<endl;
cout<<abs(d)<<endl;
}
template <teypename 標(biāo)識符>
函數(shù)定義
定義一個絕對值的模板函數(shù)
template <typename T>
T abs(T x)
{
return x<0? -x : x ;
}
void main()
{ int n=-5;
float d=56.4;
cout<<abs(n)<<endl;
cout<<abs(d)<<endl;
}