编译出现错误:error C2912: explicit specialization; 'void __cdecl returnAddress(char *[],int)' is not a function template,我就是检查不出returnAddress这个函数哪里错了?
#include <iostream>
#include <cstring>
using namespace std;
template <typename any>
any maxn(any arr[],int n);
template <> void returnAddress(char* arr[],int n);
int main()
{
int intarr[6]={21,35,74,665,92};
double doublearr[4]={213.24,364.76,314,57};
int x=maxn(intarr,6);
int y=maxn(doublearr,4);
char* strarr[5]=
{
{"yi chun xue yuan"},
{"bushiw o a"},
{"zm gao de"},
{"shenme wanyi"},
{"Game Programming all in one"}
};
returnAddress(strarr,5);
return 0;
}
template <typename any>
any maxn(any arr[],int n)
{
any maxNum;
maxNum=arr[0];
for(int i=1;i<n;i++)
{
if(arr[i]>maxNum)
maxNum=arr[i];
}
return maxNum;
}
template <> void returnAddress(char* arr[],int n)
{
int len=strlen(arr[0]);
int i;
for(i=1;i<n;i++)
{
if(strlen(arr[i])>len)
len=strlen(arr[i]);
}
cout<<arr[i]<<","<<&arr[i]<<endl;
}