• 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: Matt Neuburg <email@hidden>
  • Date: Sun, 12 Sep 2004 10:38:48 -0700

On Sat, 11 Sep 2004 15:30:26 -0500, Tim Hart <email@hidden> said:
>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

It works if you cast foo down to a Bar*. I had the same problem a couple of
years ago, and was straightened out by Mike Shields:

<http://www.cocoabuilder.com/archive/message/2002/10/24/71216>

As I said at the time, the docs on this could do with some better
explanation. m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



 _______________________________________________
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>
  • Prev by Date: Re: custom NSView problem
  • Next by Date: Re: New ML List Software
  • Previous by thread: Re: @protected variable access
  • Next by thread: Re: @protected variable access
  • Index(es):
    • Date
    • Thread