Question about 'const' functions, c++
I understand that when I declare a membe开发者_C百科r 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 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.
精彩评论