模板的显示具体化(指针数组)
#include "stdafx.h"#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<array>
#include<ctime>
#include<fstream>
#include<cstdlib>
#include<cctype>
using namespace std;
template<typename T>
T max(T *a,int n);
template<> char *max<char *>(char *p[], int n);
int main()
{
int b[6] = { 1,2,3,4,5,6 };
double c[4] = {1.1,2.2,3.3,4.4};
const char *d[5] = {"a","bce","de","fg","a"};
cout << max(b,6) << endl;
cout << max(c,4) << endl;
cout << max(d, 5) << endl;
return 0;
}
template<typename T>
T max(T *a,int n)
{
T max = a[0];
for (int i = 1; i < n; i++)
{
if (a[i] > max)
max = a[i];
}
return max;
}
template<>char *max<char *>( char *p[], int n)
{
int max = strlen(p[0]);
char *t = p[0];
for (int i = 1; i < n; i++)
{
if (strlen(p[i]) > max)
{
max = strlen(p[i]);
t = p[i];
}
}
return t;
}
具体化的是返回最长的字符串的地址
标红的类型应该怎么写才能进入具体化。char **编译不能通过 char *又不是对应的类型