今天寫程序的時候,,本來準備實現(xiàn)模板函數(shù),,在函數(shù)寫完后發(fā)現(xiàn),,自己寫的模板無法使用。
template <typename _type >
bool func(int num, char val)
{
? _type temp;
? temp[num] = val;
? return true;
}
上面是類似的一個函數(shù),這個函數(shù)實際上沒法使用。
使用類模板改寫成類的靜態(tài)成員:
template <typename _type >
class cfunc
{
? static bool func(int num, char val)
? {
??? _type temp;
? ? temp[num] = val;
??? return true;
??
}
};
使用:
? bool ret = cfunc<type>::func(num, val);
但是感覺還是不夠舒服。