Le 26 mai 2010 à 14:53, Graham Cox a écrit :

> 
> On 26/05/2010, at 10:41 PM, vincent habchi wrote:
> 
>> Hmmm... Let's say you have a class A with a private variable "priv" and b a 
>> pointer to a subclass of A. Is:
>> 
>> [(A *)b priv]
>> 
>> legal?
> 
> 
> No. It's not legal syntax for accessing an ivar in any case - square brackets 
> invoke a method:- [instance method]. Obj-C does not have the concept of 
> private/public/protected methods, unlike C++.
> 
> Perhaps you could ask is:
> 
> (A*)b->priv legal?
> 
> Depends. If priv is @private it is invisible to code other than within the 
> methods of class A itself, so if this code lived inside such a method it 
> would work, otherwise it would not. I don't think the cast makes any 
> difference.

Just for the record, to be exact, @private ivar is invisible to code other than 
within the class A @implementation. You can access private ivars from a plain C 
function defined in the class A @implementation block.

> But this is not getting to the problem that the OP is having, which AFAICS is 
> unrelated to @private. @private is a Good Thing™ - often worth using.
> 
> --Graham


-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to