May 15, 2010 at 1:44pm UTC
this code generate 4-errors when i build this program. please give solution to this problem
#include<iostream>
using namespace std;
class SMember
{
static int a;
public:
static void get()
{
a=40;
}
static void show()
{
cout<<"a = "<<a<<endl;
}
};
static void main()
{
SMember::get();
SMember::show();
}
May 15, 2010 at 1:53pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include<iostream>
using namespace std;
class SMember
{
private :
static int a;
public :
static void get()
{
a=40;
}
static void show()
{
cout<<"a = " <<a<<endl;
}
};
//you also have to globally declare
//the static variable
int SMember::a;
//and use int main
int main()
{
SMember::get();
SMember::show();
cin.get();
return 0;
}
Last edited on May 15, 2010 at 1:54pm UTC