O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required