#include
#include
#include
using namespace std;
template
T maxn(const T p[], T n);
int main()
{
int x[4] = {1,2,5,4};
double y[6] = { 9,-1,25,213,1,23 };
char* z[5] = { "asfd","wqeqwerqw","ads","ssssssss","d" };
cout << maxn(x, 4) << endl;
cout << maxn(y, 6.0) << endl;
cout << maxn(z, 5) << endl;
system("pause");
return 0;
}
template<>const char* maxn(const char* arr[], unsigned n)
{
unsigned idxMax = 0;
for (unsigned i = 0; i < n; ++i) {
if (strlen(arr[i]) > strlen(arr[idxMax])) {
idxMax = i;
}
}
return (arr[idxMax]);
}
template
T maxn(const T p[], T n)
{
int max = 0;
for (T i = 1; i
{
max = p[max] > p[i] ? max : i;
}
return p[max];
}
总是说没有与模版匹配的 maxn实例,用的vs2015 求解。。。