与普通函数区别:1.多了个template<class T>;2.某些确定类型变不确定类型T
一:引子:
#include<iostream>
using namespace std;
template<typename T>
T Max(T a, T b)
{
return a > b ? a : b;
}
int main()
{
int x, y;
double a, b;
cin >> x >> y >> a >> b;
cout << Max(a, b) << "\n" << Max(x, y);
}
结果:














![【19年扬大真题】已知a数组int a[ ]={1,2,3,4,5,6,7,8,9,10},编写程序,求a数组中偶数的个数和偶数的平均值](https://img-blog.csdnimg.cn/ad68b231895b499da1b73793514c1236.png)





