I apologize if this has been asked before. My search results did not turn up a similar question.
This is a conceptual question. According to MSDN and others as well:
A constant member function cannot modify any data members or call any member functions that aren’t constant
Why then are we allowed to access static member variables from a const method?
The C++ standard says this about
constmember functions:So you see that only non-static data members are part of the ‘constness’ of the member function.
However, I think that more importantly it indicates that a good way to understand what’s going on with
constmember functions is that it makes the implicitthispointer a pointer toconst.Since static members don’t need to be accessed via the
thispointer (implicitly or explicitly), access to them isn’tconstqualified.