Ad Code

we will have to use Static Data members?

In which situation we will have to use Static Data members?


The declaration of a static data member in the member list of a class is not a definition. You must define the static member outside of the class declaration, in namespace scope. For example:

class X
{
public:
      static int i;
};
int X::i = 0; // definition outside class declaration

Once you define a static data member, it exists even though no objects of the static data member's class exist. In the above example, no objects of class X exist even though the static data member X::i has been defined.
Reactions

Post a Comment

0 Comments