The minimal example of the problem I'm having is reproduced below:
#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;
}
With the error error: assignment of data-member ‘foo::value’ in read-only structure
. I feel like I'm missing something simple here, but why am I unable to modify the member x
in my class?