• 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: @protected variable access
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @protected variable access


  • Subject: Re: @protected variable access
  • From: email@hidden
  • Date: Mon, 13 Sep 2004 09:27:50 -0700

Tim Hart wrote:
| Assume the following:
|
| @interface Foo :NSObject
| {
|   @protected
|            int i;
| }
|
| @end
|
| @interface Bar : Foo
|
| -(id) initWithFoo:(Foo*)foo;
|
| @end
|
|
| So we have Bar as a subclass of Foo, but also initializable with an
| instance of Foo - a quasi-copy initializer.
|
| I was under the impression that initWithFoo could legally do the
| following:
|
| @implementation Bar
|
| -(id) initWithFo:(Foo*)foo
| {
|   i = foo->i;//legal access to a protected member.
| }
| @end
|
| I know such access is legal in Java.

Because "protected" in Java means something else entirely: "accessible to subclasses *and* other classes in the same package". It adds "accessible to subclasses" to the not-quite-public access granted by the (default) package access.


| My C++ is a bit rusty, but I'm
| nearly certain it's legal there as well.

No, it's not. In C++, "protected" allows access to otherwise-private variables only for the accessing object itself, not to those of other objects. That is, it allows access only through the "this" pointer.


Glen Fisher


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: @protected variable access
      • From: Tim Hart <email@hidden>
References: 
 >@protected variable access (From: Tim Hart <email@hidden>)

  • Prev by Date: Re: New ML List Software
  • Next by Date: Re: Getting the background colour for NSBox?
  • Previous by thread: Re: @protected variable access
  • Next by thread: Re: @protected variable access
  • Index(es):
    • Date
    • Thread