Accessing Non static data member from static member function

class A {
public:
static int i;
int j;
static void foo() {
A a;
a.j = 6;
}
A() {
j = 6;
}
};

The above code is valid Because there are two scope with in the foo function

the other is of the object that is being made.  so its valid to call a.j from foo()
P.S ( This sorta question was asked from me in some interview and i was like no u

cant access non static data member from static function )

Advertisements

~ by Azeem on May 5, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: