I'm having an issue. I have a class with an overloaded operator like this..
class Foo
{
friend bool operator<(const Foo &a, const Foo &b);
...
};
bool operator<(const Foo &a, const Foo &b)
{
return a.member < b.member;
}
Then in a function in a class that holds some Foos in a map as keys...
void Bar::Update()
{
for (FooItr itr = foos.begin(); itr != foos.end();) {
FooItr test = itr++;
if (!test->first.Check()) { // Check() is const
my_map.insert(*test);
foos.remove(test);
}
}
for (MapItr itr = my_map.begin(); itr != my_map.end(); ++itr) {
itr->first.Update(); // Update is not const
}
}
and I get an error message like...
error: passing ‘const Foo’ as ‘this’ argument of ‘void Foo::Update()’ discards qualifiers
I believe the reason is that the my_map.insert() is inserting const Foos, but I don't know how to solve this issue.