static
The reserved static has several uses in C++
The simplest is to extend the lifetime of a variable.
reference
These are variables that are local to a function.
The definition is proceeded by the keyword
static
function Foo() { static int callCount{0}; }
On first call to the function
The variable is initialized.
Or the constructor if it is a class.
When the function exits, the static variable does
NOT
go out of lifetime.
The value is preserved across calls.
The destructor is only called when the program exits.
This can be extended to classes as well.
But the operation is different.
Static data members shared across all instances of a class.
Static member DO NOT need a instance of the class to be created to be called.
Static member functions are discussed on 306
They are shared across all instances of the class.
They do have access to static members.
But they don't have access to non-static member variables.
Or the *this pointer
Or anything else that is part of an individual instance of a class.
Static constants
Must be initialized when declared but
Ints no problem.
Others must either be
inline
Or declared outside of the class declaration block.
Static members are discussed on 314
Again shared across all instances.
Can be declared inline or outside of the block.
But why do I want this?
Look at the chapter on debugging (P 1050)
I have an abbreviated version in the code directory