|
From: Matthias B. <fli...@gm...> - 2008-02-06 16:10:02
|
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
|