Reputation: 5452
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!
Upvotes: 0
Views: 69
Reputation: 20706
The const
refers 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 the this
instance, and it can only call static and const methods of this
, but it has full access to the global scope.
Upvotes: 1