星期日, 8月 26, 2007

Function Template

/*
請使用function template的功能,

寫出名為cubic的樣板函式
他的功能是算出數入數值的立方,
並以完整程式驗證
分別輸入int,float,double 3種資料type的數值
*/
Ex 1:
template <class T>
T cubic(T a)
{
return a*a*a;
}

====>>cubic(變數)

Ex 2:
template <class T,class T2>
double times(T a,T2 b) //T ==> double
{
double sum=a*b;
return sum;
}
===>>times(變數a,變數b)

沒有留言: