Static Member Functions

You cannot have static and nonstatic member functions with the same names and the same number and type of arguments.

A static member function does not have a this pointer. You can call a static member function using the this pointer of a nonstatic member function. In the following example, the nonstatic member function printall() calls the static member function f() using the this pointer:

// This example illustrates a static member function f().

#include <iostream.h>
class c {
            static void f() { cout << "Here is i"
                                        << i << endl;}
            static int i;
            int j;
      public:
            c(int firstj): j(firstj) {}
            void printall();
            };
void c::printall() {
      cout << "Here is j " << this->j << endl;
      this->f();
      }
int c::i = 3;
void main() {
      class c C(0);
      C.printall();
      }

A static member function cannot be declared with the keyword virtual.

A static member function can access only the names of static members, enumerators, and nested types of the class in which it is declared.



Using the Class Access Operators with Static Members


Member Functions
Static Data Members
Static Members
The this Pointer
Virtual Functions