![](/img/trans.png)
[英]Explicit specialization - template-id does not match any template declaration
[英]template id does not match any template declaration
我正在尝试编写一个函数模板,该函数模板从值数组中返回最大值。 还应该有一个专门的模板,该模板接受一个指向chars的指针数组,并返回该数组元素所指向的最大字符串的地址。 我收到错误“ [char max(char **,int)”的[[Error] template-id'max'与任何模板声明都不匹配”。 我真的不确定模板专业化中有什么问题,也不想重载该函数,我想知道为什么这段代码无法正常工作。
我的代码:
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
//returns the maximum value out of an array
template `<typename T>`
T max(T array[], int items);
//returns returns address of largest string pointed to by an element in the array
template <>
char * max <char>(char * array[], int items);
int elemcout();
int main(){
double list [] = {2.4, 5.7, 3.6, 8.1, 10.6, 15.7, 3.1415};
int items []= {20,50,10,30,40};
cout << max(list, 7) <<endl <<max(items, 5);
}
template <typename T>
T max (T array[] ,int items){
T cmax = 0;
for (int i = 0; i < items; i++){
if (array[i] > cmax)
cmax = array[i];
}
return cmax;
}
template <>
char * max <char>(char array[], int items){
//was working on this but got template missmatch error
}
如果T
为char*
,则签名应为char* max<char*>(char* array[], int items)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.