c++ - Const method accessing static variables -


i apologize if has been asked before. search results did not turn similar question.

this conceptual question. according msdn , others well:

a constant member function cannot modify data members or call member functions aren't constant

why allowed access static member variables const method?

the c++ standard says const member functions:

if member function declared const, type of const x*, [...]

in const member function, object function called accessed through const access path; therefore, const member function shall not modify object , non-static data members.

so see non-static data members part of 'constness' of member function.

however, think more importantly indicates way understand what's going on const member functions makes implicit this pointer pointer const.

since static members don't need accessed via this pointer (implicitly or explicitly), access them isn't const qualified.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -