|
/* Example For Static Function And Static Variable */
/* Simple Code for showing Usage Of Static Variable and Function */
#include<iostream.h>
#include<conio.h>
class stat
{
private:
static int a;
public:
static void inc(void);
};
int stat :: a; //redeclaration of static variaable outside the class
void stat::inc(void)
{
a++;
cout<<"nObject "<<a<<" is createdn";
cout<<"value="<<a<<endl;
}
void main()
{
clrscr();
stat obj1;
stat::inc();
stat obj2;
stat::inc();
getch();
}
|
|