4

I saw something like:

const char& operator[] (int Index) const

the first const I understand. It's to protect the returning char from being modified.

But what does second const mean? Why do we sometimes use two const, sometimes just one?

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
Yiou
  • 770
  • 1
  • 10
  • 19
  • See also http://stackoverflow.com/questions/19237411/const-and-non-const-operator-overloading?rq=1 – Mat Mar 17 '14 at 16:31

1 Answers1

7

It can be used for any member function, not only operators. It means, that this function will:

  • not be able to modify any data members (except mutable ones)
  • will not be able to call any non-const member functions
Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187