One of the most viewed questions here on SO is the question that deals with overloading of various operators. There is something I don't understand about the overloading of brackets operator operator[]. My question is about the following code:
class X {
value_type& operator[](index_type idx);
const value_type& operator[](index_type idx) const;
// ...
};
Here the operator is overloaded twice, one function which allows the change of members and one which does not. I read that c++ doesn't allow function overloading by return type, but this looks like it. T& is changed to const T&. Can someone explain to me what exactly is this "overloading" called and why does this work?
Thanks in advance.
PS: If this works because the second const keyword changes the "invisible" this pointer argument to const this then I understand, but still, is there a name for that practice?