1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <string>
using namespace std;
template<typename T>
T MaxFunc(T Arr[], int sz)
{
T Temp[sz] = T Arr[0];
for (int i = 1; i < sz; i++)
{
if (T Arr[i] > Temp)
{
Temp = T[i];
}
}
return(Temp[]);
}
int main()
{
int IntArr[5] = { 4, 1, 13, 3, 2 };
double DoubleArr[5] = { 1.14, 8.1, 5.2, 2.3 };
string StringArr[5] = { "the", "student", "is", "in", "class" };
cout << MaxFunc<int>(IntArr, 5);
cout << MaxFunc<double>(DoubleArr, 5);
cout << MaxFunc<string>(StringArr, 5);
}
|