[Error] template-id 'maxn<>' for 'void maxn(const char**, int)'

守夜人jedi 2023-05-20 18:34:19
#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)'

劳烦大神指正。

...全文
81 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,849

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧