Valveman 2023-04-04 14:58 采纳率: 69.2%
浏览 86
已结题

E0304 没有参数列表与函数模板匹配的问题


#include<iostream>
#include<set>
#include<algorithm>
#include<functional>
using namespace std;


template<class T>
void display(char* name, T& t)
{
    cout << name;
    multiset<int>::iterator it = t.begin();
    while (it != t.end())
    {
        cout << *it++ << endl;
    }
    cout << endl;
}

void main()
{
    int a[] = { 1,8,9,5,4,6,7 };
    int size = sizeof(a) / sizeof(int);
    multiset<int>T1;
    for (int i = 0; i < size; i++)
        T1.insert(a[i]);
    display("s1=", T1);

    system("pause");
}

img


问题是出在display("s1=",T1)那里。
上面是我的代码,下面是我出现的问题,这个display函数的作用是把这个multiset的容器里面的元素输出出去,为什么会出现这种问题,希望大家能帮我解决下谢谢了。

  • 写回答

2条回答 默认 最新

  • 元气少女缘结神 2023-04-04 15:14
    关注

    你子函数定义模板并没有用到,直接这样就行了:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月12日
  • 已采纳回答 4月4日
  • 修改了问题 4月4日
  • 创建了问题 4月4日