Re: @protected variable access
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