I understand that when I declare a member function as const I actually say that I will not change the class. My question – does ‘class’ refer to (*)this instance or to the class in general?
For exmaple – if I have a const member function that create a new instance of the same class and edit this instance, is that legal?
thanks!
The
constrefers to the instance on which you call the function, which is also why static member functions cannot be declared const. A const function can read, but not write, the fields of thethisinstance, and it can only call static and const methods ofthis, but it has full access to the global scope.