5

I tried doing this:

std::set< pair<int, int> > mySet;

// fill the set with something

mySet.find( make_pair(someValueX, someValueY) )->first = newX;

But I get the following error on compilation:

error: assignment of member 'std::pair<int, int>::first' in read-only object|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===||
Tudor Versoiu
  • 122
  • 2
  • 8

1 Answers1

8

Members of std::set are const, because changing them could make their ordering invalid. You would have to erase the pair and re-insert it after it was changed.

alain
  • 11,939
  • 2
  • 31
  • 51