定义函数模板的一般形 式为
template < typename T> 或 template <class T>
函数模板: 函数参数个数,函数体相同.参数类型不同
函数重载: 函数参数个数,类型不同.与函数类型(返回值)无关
#include <iostream>
using namespace std; template<typename T>
T max(T a, T b, T c)
{
if(b > a) a = b;
if(c > a) a = c;
return a;
} int main()
{
int x, y, z, m;
cout << "please enter three integer numbers:" << endl;
cin >> x >> y >> z;
m = max(x, y ,z);
cout << "integer of max is " << m << endl; double x1, y1, z1, m1;
cout << "please enter three double numbers:" << endl;
cin >> x1 >> y1 >> z1;
m1 = max(x1, y1 ,z1);
cout << "double of max is " << m1 << endl; long x2, y2, z2, m2;
cout << "please enter three long numbers:" << endl;
cin >> x2 >> y2 >> z2;
m2 = max(x2, y2 ,z2);
cout << "long of max is " << m2 << endl;
return ;
}