1 #include<iostream> 2 using namespace std; 3 template<typename T>//定义一个通用函数,T为类型参数 4 5 6 T max(T a, T b, T c)//只能用在参数个数相同,参数类型不同 7 { 8 if (b > a) a = b; 9 if (c > a) a = c; 10 return a; 11 } 12 13 int main() 14 { 15 int i1 = 185, i2 = -76, i3 = 567, i; 16 double d1 = 56.87, d2 = 90.23, d3 = -3214.78, d; 17 long l1 = 67854, l2 = -912456, l3 = 673456, l; 18 19 i = max(i1, i2, i3); 20 d = max(d1, d2, d3); 21 l = max(l1, l2, l3); 22 23 cout << "i_max=" << i << endl; 24 cout << "d_max=" << d << endl; 25 cout << "l_max=" << l << endl; 26 while (1); 27 }