#include<iostream.h>
#include<conio.h>
class temp
{
int t;
static s;
public:
void set(int x)
{
s=t=x;
}
static void sinc()
{
s++; //static member function can access only static members
//t++; //t is not increment here because
//t is not a static variable
}
void inc()
{
t++;
s++;
}
void show()
{
cout<<"Static variable = "<<s<<endl;
cout<<"Normal variable = "<<t;
}
};
int temp::s;
void main()
{
clrscr();
temp t1;
int data,n;
cout<<"Enter data =";
cin>>data;
t1.set(data);
cout<<"Enter number of itteration = ";
cin>>n;
for(int i=0;i<n;i++)
{
temp::sinc();
t1.inc();
}
t1.show();
getch();
}
No comments:
Post a Comment