class A
{
void func();
};
int main()
{
std::set<A> set;
...
std::set<A>::iterator i;
for(i=set.begin();i!=set.end();++i)
{
(*i).func(); //Offending line
}
...
}
class A
{
void func() const;
}
...
class A
{
void func();
};
int main()
{
std::set<A> set;
...
std::set<A>::iterator i;
for(i=set.begin();i!=set.end();++i)
{
(*i).func(); //Offending line
}
...
}
class A
{
void func() const;
}
...
#include <set>using std::set;#include <iostream>using std::cout;using std::endl;#include <cstdlib>#include <ctime>class A{public: A(const long unsigned int src_x) { x = src_x; } void func(void) { x += rand(); } const bool operator<(const A &rhs) const { if(x < rhs.x) return true; return false; } long unsigned int x;};int main(void){// srand(time(0)); set<A> s; s.insert(A(2)); s.insert(A(1)); s.insert(A(4)); // Print out original value, then alter it. for(set<A>::iterator i = s.begin(); i != s.end(); i++) { cout << i->x << endl; i->func(); } // Print out new value. for(set<A>::iterator i = s.begin(); i != s.end(); i++) { cout << i->x << endl; } return 0;}
Quote:Original post by LonelyStarYeah that's fine then, though it does suggest a map may be more appropriate.
Hello,
Well, since the members I want to change do not effect the order of the elements, I will just make them mutable.
Thanks for your help!
Nathan
Quote:Original post by iMalc
Yeah that's fine then, though it does suggest a map may be more appropriate.