5.4. Static Member Functions

A special member function (called a static member function) enables you to access class static data members. The format is

class Class_name {
   . . .
   static Type function_name(signature);      // static member function
   . . .
};

Static member functions allow access to static data members without callers instantiating objects. Static member functions do not have a this pointer, making access to nonstatic data impossible. (Which object's class data would they access?) To call a static member function without object notation, use the scope operator (::), as follows.

					Class_name::function_name(argument_list); 

You may also call static member functions with an object (using .) or a pointer to an object (using ->), but the object's ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.