This is the key point about static member functions: They can't access anything particular to the instance through which they're called, and in fact you can call them without specifying any instance at all. In C++, the static member function foo() of class bar could be called like so: bar::foo(), and it could also be called through instance baz of that class: baz.foo().
What use is a static member function? Good question. You might have one or more static data members 1, in which case you might want to protect them from subclasses by making them private and allowing access only through a safe and sane procedural interface. There are a few reasons why a class might want to have data common to all instances of the class. You might also have a function which is specific to your class and which ought to be closely associated with it, but which doesn't need to access the data members of any particular instance.
Another use is this, and it's the only one I've found consistently useful: If you're making class wrappers for a "message" based windowing API (Win32, for example), how do you route messages to the correct class instance? The gory details are a matter for another writeup: Window Class Library.
F'rinstance, I once wrote some undo
es which had static data member
s that tracked the total amount of memory allocated
by all living instance
s of class
es anywhere in the hierarchy
. When they allocated memory
, they'd add to the total, and when they freed memory
, they'd subtract from the total. This allowed me to set a limit on the total memory
used by the whole mess, and to enforce it accurately. The static member functions
handling the count would nibble away at the bottoms of the stack
s when I went over the limit. A better way might have been to define a class
that would handle the count and notify the stack
s when they needed to prune themselves. I could then have had several independent and unrelated sets of undo
information; just pass around pointers to memory
s as needed. But I digress