• 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: howto mix objc/c++ in a nice way?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: howto mix objc/c++ in a nice way?


  • Subject: Re: howto mix objc/c++ in a nice way?
  • From: Simon Strandgaard <email@hidden>
  • Date: Thu, 10 Nov 2005 21:21:11 +0100

On 11/10/05, Simon Strandgaard <email@hidden> wrote:
> On 11/10/05, Simon Strandgaard <email@hidden> wrote:
> > How to let B.test() access A's internals, without
> > using (void*) and reinterpret_cast?
>
> I should add that the header file is used in objc projects, so
> its not an option for me to change to objc++ mode for all the
> files that includes it.
>
> Any ideas?

Derrick Bass helped me out. Thanks.

The solution was to use (struct AInner*) in the header file,
and (AInner*) in the implementation file. See code below.

--
Simon Strandgaard


// in .h file
struct AInner;
@interface A : NSObject {
	struct AInner* _inner;
}
-(id)init;
-(struct AInner*)inner;
@end

@interface B : NSObject {
}
+(void)test:(A*)a;
@end



// in .mm file
class AInner {
public:
	int _value;
};
@implementation A
-(id)init {
	_inner = new AInner;
	_inner->_value = 42;
	return self;
}
-(AInner*)inner {
	return _inner;
}
@end // A



// in same .mm file
@implementation B
+(void)test:(A*)a {
	AInner* inner = [a inner];
	printf("the value is %i.", inner->_value);
}
@end // B
 _______________________________________________
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

References: 
 >howto mix objc/c++ in a nice way? (From: Simon Strandgaard <email@hidden>)
 >Re: howto mix objc/c++ in a nice way? (From: Simon Strandgaard <email@hidden>)

  • Prev by Date: Re: NSLock locking order;
  • Next by Date: MVC and NSBezierPath encoding?
  • Previous by thread: Re: howto mix objc/c++ in a nice way?
  • Next by thread: Speeding up creation of NSDictionary from XML? (iTunes related)
  • Index(es):
    • Date
    • Thread