我的函数void show(const SOP & sop)
通过调用一个不同的show函数输出一组有序对,该show函数输出下面定义的有序对,这告诉我代码C2100存在非法间接错误,但我不是确定为什么会这样。
SOP代表一组有序对。 OP代表有序对。 感谢所有帮助。
#include <algorithm> // pair
#include <iostream>
#include <set> // set
#include <cassert> // assert
#include <iterator>
using namespace std;
typedef pair<unsigned, unsigned> OP;
typedef set<OP> SOP;
void show(const OP & op);
void show(const SOP & sop);
int main() {
show(OP(7,3));
SOP x((1, 1), (3, 2), (5,4));
show(x);
}
void show(const OP & op) {
cout << "(" << op.first << "," << op.second << ")" << endl;
}
void show(const SOP & sop) {
for (const OP & n: sop) {
show(n);
}
}
答案 0 :(得分:2)
这段代码
SOP x((1, 1), (3, 2), (5, 4));
应该使用括号而不是括号
SOP x{{1, 1}, {3, 2}, {5, 4}};
有了这种改变,一切似乎都井然有序。