错误:对"set_union"的调用不匹配

Error: No matching for call to "set_union"

本文关键字:调用 不匹配 union set 错误      更新时间:2023-10-16

我今天正在研究一个算法问题([Uva 12096](,我用我的指导书写了一个代码。这就像书上的代码一样,但是当我编译它时发生了错误:[错误]没有匹配函数来调用"set_union(, std::set::iterator, , std::set::iterator, std::insert_iterator>("。

我使用 diff 来查找我的指南显示的代码是否有任何不同,但我找不到任何区别。我哪里做错了?我该如何解决这个问题?UVA 12096

#include<iostream>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
#define ALL(x) x.begin, x.end()
#define INS(x) inserter(x,x.begin())
typedef set<int> Set;
map<Set, int> IDcache; 
vector<Set> Setcache;
int ID(Set x){
    if(IDcache.count(x))    return IDcache[x];
    Setcache.push_back(x); 
    return IDcache[x] = Setcache.size() - 1;
} 
int main(){
    int T;
    cin >> T;
    while(T--){
        stack<int> s;
        int n;
        cin >> n; 
        for(int i = 0; i < n; i++){
            string op;
            cin >> op;
            if(op[0] == 'P')    s.push(ID(Set()));
            else if(op[0] == 'D')   s.push(s.top());
            else{
                Set x1 = Setcache[s.top()]; s.pop();
                Set x2 = Setcache[s.top()]; s.pop();
                Set x;
                if(op[0] == 'U') set_union  (ALL(x1), ALL(x2), INS(x));//Error occured here.
                if(op[0] == 'I') set_intersection   (ALL(x1), ALL(x2), INS(x));//Error also occured here.
                if(op[0] == 'A') {
                    x = x2;
                    x.insert(ID(x1));
                }
                s.push(ID(x));
            }
        cout << Setcache[s.top()].size() << endl;
        }
    cout<<"***"<<endl;  
}
    return 0;
}

您的ALL宏包含错误,您缺少几个参数。

#define ALL(x) x.begin, x.end()应该是#define ALL(x) x.begin(), x.end().