Monday, December 17, 2018

Static Member Function

CODE:


#include<iostream>

using namespace std;


class test
 {
    int code;
      static int count;               //static member variable
   public:
      void setcode()
      {
      code=++count;
  }
  
  void showcode()
  {
  cout<<"object member: "<<code<<endl;
  }
  
  static void showcount()           //static member function
  {
  cout<<"count= "<<count<<endl;
  }
};

int test::count;

int main()
{
test t1,t2;

t1.setcode();
t2.setcode();

test::showcount();                 //acccessing static function

test t3;
t3.setcode();
test::showcount();

t1.showcode();
t2.showcode();
t3.showcode();

return 0;
}



OUTPUT:




No comments:

Post a Comment

Static Member Function

CODE : #include<iostream> using namespace std; class test  {     int code;       static int count;               //static...