C++ Static member method call on class instance

The standard states that it is not necessary to call the method through an instance, that does not mean that you cannot do it. There is even an example where it is used:

C++03, 9.4 static members

A static member s of class X may be referred to using the
qualified-id expression X::s; it is
not necessary to use the class member access syntax (5.2.5) to refer
to a static member. A static member
may
be referred to using the class member access syntax, in which
case the object-expression is
evaluated.

class process {
public:
   static void reschedule();
};

process& g();

void f()
{
   process::reschedule(); // OK: no object necessary             
   g().reschedule(); // g() is called
}

Leave a Comment