用函数模板:求两个short型的数据和、两个int的数据和以及两个float的数据和。

如题所述

#include "stdio.h"
template<typename T>
T func(T a,T b)
{
 return a+b;
}
int main()
{
 short a=10,b=23;
 int m=20,n=34;
 float i=1.2,j=9.0;
 printf("%d\n",func<short>(a,b));
 printf("%d\n",func<int>(m,n));
 printf("%f\n",func<float>(i,j));

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-05-10
是用C++的重载,还是用c?
相似回答