c++ - 错误:对“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;
}
解决方案
您的ALL
宏包含错误,您缺少几个括号。
#define ALL(x) x.begin, x.end()
应该是#define ALL(x) x.begin(), x.end()
。
推荐阅读
- sas - 函数 LAG 中的动态 n
(变量)SAS_part2 - python - subprocess.Popen 不断询问 ssh-copy-id 命令的密码
- c# - 从 Asp.Net Core 2.1 Web 应用程序的 SQL 迁移中的 Db 更新中的 NOT 关键字错误
- javascript - 得到错误 SyntaxError: expected expression, got '}' in Firefox
- java - Apache tomcat 和 servlet(初学者) - 404 错误,可能找不到类?
- elasticsearch - 如何进行正确的查询以按 ID 选择,然后使用弹性搜索进行更新?
- azure-functions - 如何在本地运行 Azure 函数时获取日志?
- node.js - 需要从数组productid[]中删除元素,该元素是mongodb集合用户的一个元素
- hugo - Hugo 为内容部分生成 URL。我该如何阻止它?
- mysql - 从大型语料库中填充句子