第一个T函数
#include
#include "stdlib.h"
#include
using namespace std;
template T co(T A[],int n);
template <> char* co(char* a[],int y);
int main()
{
int d[5]={50,10,28,5,100};
int p;
p = co(d,5);
cout << p << "\n";
char* dd[5] ={"lbsjs","jkdjkalssdjkljkl","jkkj","lihui","gougou"};
char* dw=co(dd,5);
cout << dw <<"\n";
system("pause");
return 0;
}
template
T co(T a[],int n)
{
T u;
u = a[0];
for(int i = 1;i < n;i++)
{
if (a[i] > u)
u = a[i];
}
return u;
}
template <> char* co(char* a[],int y)
{
int q,b;
q = strlen(a[0]) + 1;
for(int i = 1;i < y;i++)
{
b = strlen(a[i]) + 1;
if (b > q)
q = b;
}
for(int i = 0;i < y;i++)
{
if (strlen(a[i]) + 1 == q)
return a[i];
}
}
本文地址:http://com.8s8s.com/it/it27501.htm