In Effective C++ Item 03, Use const whenever possible.
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[] does make difference from int& operator[].
But what about:
int foo() { }
and
const int foo() { }
Seems like that they're the same.
My question is, why we use const int operator[](const int index) const instead of int operator[](const int index) const ?