PDA

View Full Version : c++ concepts




Sunil
Feb 24, 2007, 10:08 PM
why static functions can access static variables only



mufflon
Feb 24, 2007, 10:44 PM
this is really one of the shortest threads I've seen on MR and I'm not even certain it's a question or a statement... ... if you were a little bit less vague we could actually help you, if you want...

ChrisBrightwell
Feb 25, 2007, 12:33 AM
Because a static method will more than likely come into existance LONG before the non-static variable will.

lazydog
Feb 25, 2007, 05:00 AM
You can only access the non-static variables of a class if you have a pointer to a particular instance of the class.

Non-static functions of a class are always associated with a particular instance of a class and have the 'this' pointer initialised to point to the object in memory. Static functions on the other hand are not associated with any particular instance of the class and so do not have a 'this' pointer.

Sorry, that was a really bad explanation but I hope it helps a bit.

b e n