A shared variable is also called a class variable. There is one copy of it
that is shared by all instances of the class. On the other hand, instance
variables are just that; each instance of a class has it's own copy of the
instance variables declared in the class. I developed a PB library that
encapsulates all the Win32 common controls in Comctl32.dll. A function
within the dll, InitCommonControls, needs to be called once for each type of
control used in the application. Since I may use several toolbars in a
rebar control, I do not want to call InitCommonControls on the toolbar class
each time a toolbar instance is created. So I use a shared or class variable
to let me know if the toolbar class has already been initialized. Another
use for a class variable would be as an instance counter. In the
constructor for the base class the private shared variable is incremented
each time an instance of any sibling is instantiated. When the instance is
destroyed, the counter is decremented. This can be used to allocate and free
up resources used by a particular class. As for instance variables, each
instance of a class must keep it's own data because that data is unique. For
example, you create a name class with the instance variables firstName and
lastName. Since you have different names in your address book application,
you need to have each class keep it's own copy of the name, and NOT share
it; otherwise, they would all have the same firsName and lastName.