读书人

模板的运用

发布时间: 2012-10-05 15:34:34 作者: rapoo

模板的使用

1.定义一个比较两个数大小的模板

template<class Type>
Type Max(Type a,Type b)
{
if (a>b)
return a;
else
return b;
}

2.调用

int iMax=Max<int>(10,12);
double a=10.3,b=12.4;
double dMax=Max(a,b);

读书人网 >编程

热点推荐