我遇到的问题的最小例子如下:
#include <set> using namespace std; class foo { public: int value,x; foo(const int & in_v) { value = in_v; x = 0; } bool operator<(const foo & rhs) const { return value < rhs.value; } }; int main() { foo y(3); set<foo> F; F.insert(y); // Now try to modify a member of the set F.begin()->x=1; return 0; }
使用错误错误:在只读结构中分配数据成员’foo :: value’.我觉得我在这里缺少一些简单的东西,但为什么我无法修改我的课程中的成员x?