63,594
社区成员




#include <iostream>
#include <cstring>
#include <string>
#include <typeinfo>
using namespace std;
template<class T>
T maxn(T* a,int n);
template<> void maxn(const char* s[],int n);
int main()
{
// int n6[6]{21,56,89,49,258,41};
// double n4[4]{2.1,5.6,8.9,4.9};
// auto m=maxn(n6,6);
// auto n=maxn(n4,4);
// cout<<m<<endl;
// cout<<n<<endl;
const char* words[3]={"one","two","three"};
// maxn(words,3);
return 0;
}
template<> void maxn(const char* s[],int n)
{
cout<<"ok";
}
template<class T>
T maxn(T* a,int n)
{
T max=a[0];
for (int i=1;i<n;i++)
{
if (a[i]>max)
{
max=a[i];
}
}
return max;
}
我想写一个maxn的显式具体化函数,会传入一个char*数组的名称作为参数,但是我甚至没有调用函数的时候就报了如下错误:
[Error] template-id 'maxn<>' for 'void maxn(const char**, int)' does not match any template declaration
[Note] candidate is: 'template<class T> T maxn(T*, int)'
[Error] template-id 'maxn<>' for 'void maxn(const char**, int)' does not match any template declaration
[Note] candidate is: 'template<class T> T maxn(T*, int)'
劳烦大神指正。