What is static class data? - C++

What is static class data?

- Static data members of a class are declared by preceding the member variable’s declaration with the keyword static. Only one copy of static data members exist and all objects of the class share that variable. Unlike regular data members, individual copies of a static member variable are not made for each object. How many ever no of objects of a class are created, only one copy of static data member is shared amongst all of them. All static variables are initialized to zero before the first object is created.
- When a member variable is declared static within a class, it is not defined (ie storage is not allocated for it) We must provide a global definition for it outside the class. This is done by redeclaring the static variable using scope resolution operator (‘::’) to identify the class it belongs to. This causes storage for the class to be allocated.
Uses of static class data
Uses of static class data - To provide access control mechanism to some shared resource used by all the objects of a class...
What are static and dynamic type checking?
What are static and dynamic type checking? - Type checking is the operation on which the arguments that can only be applied for...
What are static variables?
What are static variables? - Static variables are the variables which has exactly one copy per class...
Post your comment