c++ concepts

Discussion in 'Mac Programming' started by Sunil, Feb 24, 2007.

  1. macrumors newbie

    Joined:
    Oct 6, 2005
    #1
    why static functions can access static variables only
     
  2. macrumors 6502

    Joined:
    Sep 15, 2006
    #2
    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...
     
  3. macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #3
    Because a static method will more than likely come into existance LONG before the non-static variable will.
     
  4. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #4
    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
     

Share This Page