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 ofconst x*, [...]in
constmember function, object function called accessed throughconstaccess path; therefore,constmember 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
Post a Comment