# include <iostream>
using namespace std;
//////// Example of static data members /////////
//int Static::x=100; if u declared static data member before class it will give you error
class Static
{
//static int x; u can also write static data member in private section
public:
static int x; // static data member
void show()
{
cout<<x++<<endl;
}
};
int Static::x=100;
int main()
{
Static s[5];
for(int i=0; i<5;i++)
{
s[i].show();
}
system("pause");
}
using namespace std;
//////// Example of static data members /////////
//int Static::x=100; if u declared static data member before class it will give you error
class Static
{
//static int x; u can also write static data member in private section
public:
static int x; // static data member
void show()
{
cout<<x++<<endl;
}
};
int Static::x=100;
int main()
{
Static s[5];
for(int i=0; i<5;i++)
{
s[i].show();
}
system("pause");
}
No comments:
Post a Comment