You might want to review the operator overload overview.
So, to recall some applicable points:
operator[] always a non-static, unified member function.- There can be several overloads, as for any other member function.
- By convention (listen to this!), Versions that do not support const will return a link to change the content (this link may be represented by a proxy type, although try to remove it).
- By convention,
const -qualified overloads can either return a const link or a copy to provide read-only access to the same elements.- Use
const -reference if the element cannot be dynamically generated, especially if it is not trivial and cheap to copy. - Use the return value if the above fails.
BTW: You really want the const and non const members to be similar, so non const can be a simple built-in function delegating another with the corresponding const_cast . <w> (Do not do this the other way around, it is not entirely acceptable or safe.)
As for your last line, it indexes a pointer to const int and returns a reference to a pointer to const char .
This is a seriously odd return value and index, although if you have the right use for it, why not?
source share