#include <iostream>
#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;
}
I want to write an explicit specialization of maxn()
that passes a char*[]
array as a parameter, but it reports the following error when I don't even call the function:
[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)'