我的函数void show(const SOP & sop)应该通过调用不同的显示函数来输出一组有序对,该函数输出下面定义的有序对,它告诉我存在非法间接寻址错误,代码为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);
}
}发布于 2019-03-03 17:53:09
所以这段代码
SOP x((1, 1), (3, 2), (5, 4));应该使用大括号而不是括号
SOP x{{1, 1}, {3, 2}, {5, 4}};有了这样的改变,一切似乎都井然有序。
https://stackoverflow.com/questions/54967508
复制相似问题