首页 > 解决方案 > 错误:对“set_union”的调用没有匹配

问题描述

我今天正在研究一个算法问题([Uva 12096]),我用我的指导书写了一个代码。和书上的代码一样,但是编译的时候出错:[Error] no matching function for call to 'set_union(, std::set::iterator, , std::set::iterator, std: :insert_iterator >)'。

我使用 diff 来查找我的指南显示的代码是否有任何不同,但我找不到任何不同之处。我哪里做错了?我怎么能解决这个问题? 乌瓦 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;
}

标签: c++stl

解决方案


您的ALL宏包含错误,您缺少几个括号。

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


推荐阅读