O'Reilly logo

Object Oriented Programming with C++, Second Edition by Sunil Patekar, Mahesh Bhave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required