Matthias Böhm wrote:
> In mingw, that won't compile, because the compiler complains that the object the iterator is pointing to is constant:
> simple.cpp: In function `int main()':
> simple.cpp:37: error: passing `const X' as `this' argument of `int X::do_something_non_const()' discards qualifiers.
> But i'm using iterator, not const_iterator!!!
This is really a question for comp.lang.c++. But, in short, your code is
probably wrong; you don't say what 'do_something_non_const' actually
does. If you've got an object in a set, you can't modify the object,
because that might affect the sorting criterion, and the object will
then be out of order in the set. that's not allowed - the system keeps
the objects in order, not you. It doesn't matter whether you use an
iterator or a const_iterator; you're not allowed to do it.
If you're really sure that 'do_something_non_const' doesn't mess up your
sorting criterion, then declare any members that do_something_non_const
changes as 'mutable', and declare do_something_non_const as const.