Web lists-archives.org

Re: [Mingw-users] set iterators are const always




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.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users