Write a program for Static Member Function

/*
  Static Member Function
*/
#include<conio.h>
#include<iostream>
using namespace std;

class Sample
{
   int code;
   static int count;
 
   public:
           void accept()
   {
      count++;
      code=count;
   }
 
   void display()
   {
    cout<<"\n\n Non Static Member: "<<code;
    cout<<"\n\n  Static Member: "<<count;
   }
 
   static void showcount()
   {
    cout<<"\n\n Static Member: "<<count;
   }
};
int Sample::count;

int main()
{
Sample s1,s2;

s1.accept();
s2.accept();

s1.display();
s2.display();

Sample::showcount();
s1.showcount();

getch();
return 0;
}

Previous
Next Post »