Thursday, 2 October 2014

Example of static data members (OOP)

 # include <iostream>
 using namespace std;

////////  Example of static data members  /////////

//int Static::x=100;        if u declared static data member before class it will give you error

class Static
{
      //static int x;       u can also write static data member in private section
      public:
      static int x;       // static data member
             void show()
             {
                  cout<<x++<<endl;
             }          
};
int Static::x=100;
int main()
{
    Static s[5];
    for(int i=0; i<5;i++)
    {
            s[i].show();
    }
    system("pause");
}

No comments:

Post a Comment