• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: class variables and class methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: class variables and class methods


  • Subject: Re: class variables and class methods
  • From: lbland <email@hidden>
  • Date: Wed, 7 Jan 2004 20:02:12 -0500

On Jan 7, 2004, at 7:04 PM, Robert Goldsmith wrote:

I assume that, if it is in the .m file, a static variable has the scope
of that file. If it is not static, it's scope is what? Global? If it is
in the .h file and static, what would it's scope be?

It's normal ANSI-C, so file scope.

No, not "easy", other than the way you just did it.

Ok, so at compile time, if there is a method that uses a static
variable, it is compiled down to use that variable even though a
subclass inherits the method and has it's own static variable :( In
other words, file scope static beats class scope static :(

If you need inheritance properties in class scope, do it using a class accessor on the static variable, ie:

in .h file:

+ (int)myClassVariable;

in .m file:

static int myClassVariable = 0;

+ (int)myClassVariable {return myClassVariable;}

-lance
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: class variables and class methods
      • From: Robert Goldsmith <email@hidden>
References: 
 >class variables and class methods (From: Robert Goldsmith <email@hidden>)
 >Re: class variables and class methods (From: Glenn Andreas <email@hidden>)
 >Re: class variables and class methods (From: Robert Goldsmith <email@hidden>)

  • Prev by Date: Re: XML and XSLT
  • Next by Date: Re: class variables and class methods
  • Previous by thread: Re: class variables and class methods
  • Next by thread: Re: class variables and class methods
  • Index(es):
    • Date
    • Thread