Static Data Members And Static Member Functions. Topics to be discussed. Static Data Members Example of Static Data Member Static Member functions Example of Static Member Function. Static Data Members.
Static Member Functions
are data objects that are common to all objects of a class.they exist only once in all objects of this class and are used when the information is to be shared
It is initialized to zero when the first object of its class is created.
There is exactly one copy of a static member for the entire class and is shared by all the objects of that class.
It is visible only within the class,but its lifetime is the entire program.
When a static data member is declared private,the non-member functions can not access this member.
Static variables are normally used to maintain values commom to the entire class.For example,a static data member can be used as a counter that records the occurrences of all the objects.
is the definition of the Static Data Member
The Static function showcount() displays the number of objects created till that moment.A count of number of objects created is maintained by the static variable count.
is executed whenever setcode() function is invoked and the current value of count is assigned to code.Since each object has its own copy of code,the value contained in code represents a unique number of its objects