Is this correct? It compiles with my compiler but I've been told it doesn't with an AIX one.
typedef std::vector<Entry>::iterator Iterator;
typedef std::vector<Entry>::const_iterator ConstIterator;
bool funct(ConstIterator& iter) const;
inline bool funct(Iterator& iter){return funct(const_cast<ConstIterator&>(iter));}
What should I do to let my code compile on the AIX platform? (Beside reimplement the non const version with Ctrl-C Ctrl-V).
const_cast
is used to remove const-ness of a variable. That is if you haveconst A& a
you can writeA& b = const_cast<A&>(a)
. Now you will be able to modifyb
or call non-const methods on it.In this case you construct a
const_iterator
from a regulariterator
and this is always possible even without using aconst_cast
. Keep in mind these are two different types and simplyconst_iterator
happened to be constructable fromiterator
C++ const-ness does not have much to do in this case.