Должен ли я вернуть const объекты?
ВEffective C++
Пункт 03, Используйте const, когда это возможно.
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
?