qgm1702 2020-05-04 23:07 采纳率: 0%
浏览 75
已采纳

在函数模板里定义了class iterator,函数模板实例化的时候,为什么泛型指针不能匹配模板呢?

 #include<iostream>
 #include<vector>
 #include<list>
using namespace std;
template <typename elemtype,class iteratortype>
iteratortype afind(iteratortype fir, iteratortype las, elemtype &value);
int main()
{
    const int size = 8;
    int arr[size]{ 1,2,3,4,5,6,7,8 };
    vector<int> vec( arr,arr + 8 );
    list<int> lis{ arr,arr + 8 };
    vector<int>::iterator iter_vec = afind(vec.begin(), vec.end(), 5);
       if (iter_vec != vec.end())
            cout << "找到了!" << endl;
    list<int>::iterator iter_lis = afind(lis.begin(), lis.end(), 4);
       if (iter_lis != lis.end())
            cout << "找到了!" << endl;
return 0;
}
template <typename elemtype, class iteratortype>
iteratortype afind(iteratortype fir, iteratortype las, elemtype &value)
{
    for (; fir != las; ++fir)
    {
         if (value == *fir)
            return fir;
        return las;
   }
}
    // 我用的vs2017 显示错误 E0304   没有与参数列表匹配的 函数模板 "afind" 实例,这是为什么?为什么泛型指针不能匹配函数摸板?
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 已采纳回答 11月23日

      悬赏问题

      • ¥15 苹果手机删除了qq软件,qq文件怎么恢复
      • ¥20 用mips 人力编程排序问题(能在mars按要求运行)
      • ¥15 Verilog小型神经网络(单层反馈神经网络)
      • ¥15 设计一个数字钟,实现时分秒的显示
      • ¥15 Clion使用头文件链接两个cpp
      • ¥15 51单片机无法触发外部中断问题
      • ¥15 基于半监督,无监督的调制识别
      • ¥15 cst求 阵列 rcs 时候 频域 时域求解器 应该怎样设置 才让两者 计算结果 相似 请附图
      • ¥15 关于#51单片机#的问题:大家帮我看一下为什么我的计时器数字一直不稳定
      • ¥15 Qt 在应用程序里总是有[PREVIEW] recv window msg, name:(Qt5QWindowIcon) hwd:(287097a)等信息不断输出,怎么解决