Accessing private members of another object of the same class
Accessing private members of another object of the same class
- Subject: Accessing private members of another object of the same class
- From: Horst Jäger <email@hidden>
- Date: Fri, 23 Jan 2009 22:01:11 +0100
Hi,
suppose I have a class with a private member as listed at the end of
this email.
Then I can access it by calling its name without an accessor function
(which would de facto make it public).
But how do I access a private member of another object of the same
class?
Or does Objective C have another concept of "private" than C/C++ ?
Thanks in advance
Horst
::::::::::::::::::::::::
PrivateClass.h
::::::::::::::::::::::::
@interface PrivateClass : NSObject {
@private int mineAlone;
}
-(int)yoursToo;
-(int)yoursTooButWithAnother: (PrivateClass *)another;
@end
::::::::::::::::::::::::
PrivateClass.m
::::::::::::::::::::::::
#import "Private.h"
@implementation PrivateClass
-(int)yoursToo{
// access via name works
return mineAlone % 3;
// I cant't use
// return [self mineAlone]
// using a getter function
// because that would make
// mineAlone accessible for
// everyone since a method
// can't be declared private
}
-(int)yoursTooButWithAnother: (PrivateClass *)another;
// what am I to do?
// return another.mineAlone % 3;
// won't work and
// return [another mineAlone] % 3;
// would de facto make it public
}
@end
::::::::::::::::::::::::
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden