#if 0
template<typename T>//模板头
//template<typename T,typename A>//模板头
T mau(T a, T b)
{
return a > b ? a : b;
}
int main()
{
int num1 = 12, num2 = 34;
cout << mau<int>(12, 34) << endl;
int(*mauint)(int, int) = &mau;
cout << mau<double>(1.2, 3.4) << endl;
double(*maudouble)(double,double)=&mau;
cout << "maxint:" << mauint <<" " << "maxdouble:" << maudouble << endl;
cout << mau<string>("hello", "world") << endl;
char s1[] = "hello";
char s2[] = "world";
cout << mau<string>("s1", "s2") << endl;//以为比地址所以觉得hello大一些
return 0;
}//模板函数 int(*mauint)(int, int) = &mau;
#endif//函数模板 值参数化 类型参数化
C++函数模板
最新推荐文章于 2024-08-15 16:09:23 发布