c++ - Is it safe to cast away const if never call any non-const methods -
is still undefined behavior cast away const pointer object if const methods ever called after cast? i'm trying implement both iterator , const_iterator class dereferenced iterator proxy object small amount of state , pointer parent object (simplified below) although const qualified proxy calls const methods on parent still requires non-const pointer in constructor. class query { public: int (int r, int c) const; void set (int r, int c, int v); class iterator { iterator (query *q, int r) : m_qry(q), m_row(r) {} row operator* const () { return row(m_qry, m_row); } query *m_qry; int m_row; }; class const_iterator { const_iterator (const query *q, int r) : m_qry(q), m_row(r) {} const row operator* const () { // protected constructor row needs cast return row(const_cast<query *>(m_qry), m_row); } const query *m_qry; int m_row; ...