5.10 STATIC DATA MEMBERS AND METHODS
After studying public and private members, let us study qualifier “static” with reference to a class. We can have static data members as well as static methods. Let us study them in detail.
5.10.1 Static data member
We have already seen that only data members are instantiated in every object. However, sometimes a data member has to have the same value for all the objects of that class. For example in class Player, logo remains the same irrespective of any instantiation of the class. The player may be Sachin or Sourav; the logo is “sahara”.
Like ordinary members, we can refer these static members with dot mechanism like sachin.logo.
If we have to reference it with the help of class name, we must use (::) operator. ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.