howto mix objc/c++ in a nice way?
howto mix objc/c++ in a nice way?
- Subject: howto mix objc/c++ in a nice way?
- From: Simon Strandgaard <email@hidden>
- Date: Thu, 10 Nov 2005 17:14:42 +0100
Hi objC++ coders,
How to let B.test() access A's internals, without
using (void*) and reinterpret_cast?
Thanks in advance.
--
Simon Strandgaard
// in .h file
struct AInner;
@interface A : NSObject {
struct AInner* _inner;
}
-(id)init;
-(void*)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;
}
-(void*)inner {
return _inner;
}
@end // A
// in same .mm file
@implementation B
+(void)test:(A*)a {
void* ptr = [a inner];
AInner* inner = reinterpret_cast<AInner*>(ptr); // can this be improved?
printf("the value is %i.", inner->_value);
}
@end // B
void maincode() {
A* a = [[A alloc] init];
[B test:a];
}
_______________________________________________
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