#include <iostream>
#include <cstring>
template<typename Type> Type maxn(Type st[], int);
template<> char* maxn<char*>(char* sst[], int n);
int main()
{
int arr[]{ 1,2,5,4,3 };
double arr_d[]{ 19.6,13,19.8,100.8,98.4 };
std::string ss[]{ "hello", "hello world!" };
std::cout << "arr[]中最大的数是:" << maxn(arr, 5) << std::endl;
std::cout << "arr_d[]中最大的数是:" << maxn(arr_d, 5) << std::endl;
std::cout << "ss[]中最大的数是:" << maxn(ss, 2) << std::endl;
return 0;
}
template<typename Type>
Type maxn(Type st[], int n)
{
Type max{ st[0] };
for (size_t i{}; i != n; ++i)
{
if (st[i] > max)
{
max = st[i];
}
}
return max;
}
template<> char* maxn<char*>(char* sst[], int n)
{
size_t pos{};
for (size_t i{}; i != n; ++i)
{
if (strlen(sst[pos]) < strlen(sst[i]))
{
pos = i;
}
}
return sst[pos];
}