static Class Members

Each object of a class has its own copy of all the data members of the class. in certain cases, only one copy of a variable should be shared by all objects of a class. The programs of Figs. 1-4 demonstrates a private static data member called count and a public static member function called getCount. Figure 4 uses function getCount to determine the number of Employee objects currently instantiated.
Figure 1: Employee class definition with a static data member to track the number Employee objects in memory.
\includegraphics[scale=0.45]{figures/img7.59.ps}
Figure 2: Employee class member-function definitions. (part 1 of 2)
\includegraphics[scale=0.45]{figures/img7.60.ps}
\includegraphics[scale=0.45]{figures/img7.61.ps}
Figure 3: Employee class member-function definitions. (part 2 of 2) and static data member tracking the number of objects of a class. (part 1 of 2)
\includegraphics[scale=0.45]{figures/img7.62.ps}
\includegraphics[scale=0.45]{figures/img7.63.ps}
Figure 4: static data member tracking the number of objects of a class. (part 2 of 2)
\includegraphics[scale=0.45]{figures/img7.64.ps}
\includegraphics[scale=0.43]{figures/img7.65.ps}
2004-07-08