Wednesday 28 January 2015

Some facts about Static data members (in C++)


Static data members can be declared private and still can be accessed. Eg :
#include <iostream>
using namespace std;
class stat
{
private:
static int p;
public:
static int Get() { return p; }
};
int stat::p;
int main()
{
stat s;
cout << s.GetValue() << endl;
}

Static data members can be accessed in the same way by static member functions.

No comments:

Post a Comment

SAY HELLO!!