In More Effective C++, the following codes are given
const String::CharProxy String::operator[] (int index) const
{
return CharProxy(const_cast<String&>(*this), index);
}
String::CharProxy::operator char() const
{
return theString.value->data[charIndex];
}
Why don't we just return a char instead of using const_cast and casting CharProxy to char later?
If I am not wrong in your case there is also the non const version to be able to both read/write the char and also as Real Fresh says to take a pointer/ref of the char.
Then it is natural to offer the same for the const version allowing to read the char (not write of course) and also take a pointer/ref (const) of the char.
You have that behavior with the std::vector std::string etc