qq_35219692 2016-07-17 11:01 采纳率: 54.5%
浏览 974

C++函数模版和显示具体化问题。

#include
#include
#include
using namespace std;
template
T maxn(const T p[], T n);
int main()
{

int x[4] = {1,2,5,4};
double y[6] = { 9,-1,25,213,1,23 };
char* z[5] = { "asfd","wqeqwerqw","ads","ssssssss","d" };
cout << maxn(x, 4) << endl;
cout << maxn(y, 6.0) << endl;
cout << maxn(z, 5) << endl;
system("pause");
return 0;
}
template<>const char* maxn(const char* arr[], unsigned n)
{
unsigned idxMax = 0;
for (unsigned i = 0; i < n; ++i) {
if (strlen(arr[i]) > strlen(arr[idxMax])) {
idxMax = i;
}
}

return (arr[idxMax]);

}
template
T maxn(const T p[], T n)
{
int max = 0;
for (T i = 1; i {
max = p[max] > p[i] ? max : i;
}
return p[max];
}

总是说没有与模版匹配的 maxn实例,用的vs2015 求解。。。

  • 写回答

3条回答 默认 最新

  • sinat_27132253 2016-07-18 13:49
    关注

    将template改为template

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料