В Effective C++ Пункт 03: Используйте константу, когда это возможно.
class Bigint
{
int _data[MAXLEN];
//...
public:
int& operator[](const int index) { return _data[index]; }
const int operator[](const int index) const { return _data[index]; }
//...
};
const int operator[] действительно отличается от int& operator[].
Но как насчет:
int foo() { }
и
const int foo() { }
Кажется, они одинаковы.
Мой вопрос: почему мы используем const int operator[](const int index) const вместо int operator[](const int index) const?