Web lists-archives.org

[Mingw-users] set iterators are const always




I'm using mingw 5.1.3, gcc 3.4.5 and with the following file, i get compiling errors which do not occur with other compilers:

------------------------------------------------------------------

#include <set>

using namespace std;

class X
{
public:
 X(int _x) : x(_x) {}
 X() : x(0) {}
 ~X() {}

 // non-const function
 int do_something_non_const() {};

 int getx() const { return x; }
protected:
 int x;
};

struct less_X : public less<X> {
 bool operator () (const X &a, const X &b) {
  return a.getx() < b.getx();
 }
};

int main()
{
 set<X, less_X> xset;

 xset.insert(X(0));
 xset.insert(X(1));

 set<X, less_X>::iterator it;

 for(it = xset.begin(); it != xset.end(); it++) {
  it->do_something_non_const();  // produces compiler error
 }

 return 0;
}
-----------------------------------------------------------------------------


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!!!


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

-------------------------------------------------------------------------
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