In the preceding code, the class StaticTest contains the static member function count. This function returns the value of the private class member but is not necessarily associated with a given object of type StaticTest.
Static member functions have external linkage. These functions do not have this pointers. As a result, the following restrictions apply to such functions:
-
They cannot access nonstatic class member data using the member-selection operators (. or –>).
-
They cannot be declared as virtual.
-
They cannot have the same name as a nonstatic function that has the same argument types.
Note |
|---|
| The left side of a member-selection operator (. or –>) that selects a static member function is not evaluated. This can be important if the function is used for its side effects. For example, the expression SideEffects().CountOf() does not call the function SideEffects. |