PROGRAM USING STATIC MEMBER FUNCTION
//program using static member function
#include<iostream.h>
#include<conio.h>
class test
{
int code;
static int count;
public:
void setcode()
{
code=++count;
}
void showcode()
{
cout<<"object member:"<<code<<"\n";
}
static void showcount()
{
cout<<"count:"<<count<<"\n";
}
};
int test::count;
void main()
{
test t1,t2;
clrscr();
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test::showcount();
t1.setcode();
t2.setcode();
t3.setcode();
getch();
}
#include<iostream.h>
#include<conio.h>
class test
{
int code;
static int count;
public:
void setcode()
{
code=++count;
}
void showcode()
{
cout<<"object member:"<<code<<"\n";
}
static void showcount()
{
cout<<"count:"<<count<<"\n";
}
};
int test::count;
void main()
{
test t1,t2;
clrscr();
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test::showcount();
t1.setcode();
t2.setcode();
t3.setcode();
getch();
}

Comments
Post a Comment