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. 2.25-2.28 demonstrates a private static data member called count and a public static member function called getCount. Figure 2.28 uses function getCount to determine the number of Employee objects currently instantiated.
Figure 2.25: 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.26: 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 2.27: 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 2.28: 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-29