• 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: is protected broken, or am I?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is protected broken, or am I?


  • Subject: Re: is protected broken, or am I?
  • From: Cameron Hayne <email@hidden>
  • Date: Thu, 10 Oct 2002 16:48:35 -0400

On 10/10/02 3:23 pm, "Matt Neuburg" <email@hidden> wrote:

> MyClass is a class with an ivar myIvar. MySubClass is a subclass of
> MyClass. myClassInstance and mySubClassInstance are instances of these two
> classes, respectively. mySubClassInstance has a reference to
> myClassInstance. In MySubClass, I say this:
>
> [myClassInstance->myIvar doStuff];
>
> And the compiler slaps my hand, saying: "instance variable `myIvar' is
> declared protected".
>
> Now, I went to some trouble to make MySubClass a subclass of MyClass
> exactly so mySubClassInstance would be able to get at myClassInstance's
> ivars. Now it appears I can't. I'd rather not make MyClass's ivars @public,
> though I will if I have to. But before I do, I'd like to know why this
> didn't work. Is it that @protected means I have access to my copy of an
> ivar but not to my super's copy of that ivar?

An object (instance of a class) has access to its own ivars and to the
non-private ivars of its superclass. (Note that ivars are protected by
default.) But this is referring to an instance accessing the internal bits
of itself - not the internal bits of some other instance which happens to be
of the same class.
You and I are both instances of the class 'Human' but that doesn't give you
access to my private parts! (or protected parts). ;-)

--
Cameron Hayne (email@hidden)
Hayne of Tintagel
_______________________________________________
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: is protected broken, or am I?
      • From: matt neuburg <email@hidden>
References: 
 >is protected broken, or am I? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: is protected broken, or am I?
  • Next by Date: Re: case-insensitive strings
  • Previous by thread: Re: is protected broken, or am I?
  • Next by thread: Re: is protected broken, or am I?
  • Index(es):
    • Date
    • Thread