• 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
Accessing private members of another object of the same class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Accessing private members of another object of the same class
      • From: Ken Thomases <email@hidden>
    • Re: Accessing private members of another object of the same class
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Start traces with CrashReporter
  • Next by Date: Re: NSTextView and front/middle/back ellipses
  • Previous by thread: Re: Turn autosaving on forever - is it OK?
  • Next by thread: Re: Accessing private members of another object of the same class
  • Index(es):
    • Date
    • Thread