I’m hunting a bug in code and I have a problem:
class a
{
public:
void foo(int a) {}
}
std::set<a*> set;
std::set<a*>::iterator it = set.begin();
it->foo(55); //gives me error:
// error: request for member ‘foo’ in ‘* it.std::_Rb_tree_const_iterator<_Tp>::operator-><a*>()’, which is of pointer type ‘a* const’ (maybe you meant to use ‘->’ ?)
Why it doesn’t allow me to use non-const function on it? What can I do to have a set of non-const pointers without using casting?
You need to dereference twice:
–
itis an iterator to a pointer. Your code would be correct if you had anstd::set<a>instead of anstd::set<a*>.