模板的使用

2014-11-23 19:26:30 · 作者: · 浏览: 22
1.定义一个比较两个数大小的模板
template
Type Max(Type a,Type b)
{
if (a>b)
return a;
else
return b;
}
2.调用
int iMax=Max(10,12);
double a=10.3,b=12.4;
double dMax=Max(a,b);