Sunday, January 1, 2012

Demo of static member function in 'C++'

Example



#include<iostream.h>
#include<conio.h>
#include<math.h>
class statfun
{
static int count;
int no,no1;
public:
void getdata()
{
  cout<<count++<<endl;
}
static void getcount()
{
cout<<"count:"<<count<<endl;
}
};
int statfun::count;
int main()
{
statfun s1,s2;
clrscr();
s1.getdata();
statfun::getcount();
s2.getdata();
statfun::getcount();
s1.getdata();
s1.getcount();
s1.getcount();

getch();

return 0;
}
/*===================================================================
OUTPUT
0
count:1
1
count:2
2
count:3
count:3
*/

No comments:

Post a Comment