Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top