Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created June 1, 2009 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akio0911/121363 to your computer and use it in GitHub Desktop.
Save akio0911/121363 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
class HelloWorld;
@interface PLog:NSObject {
HelloWorld *ptr;
}
- (void)sayHello;
- (void)sayHi:(HelloWorld *)p;
- (id) init;
- (void) dealloc;
@end
class HelloWorld {
id printLog;
public:
HelloWorld(bool b) { if(b) printLog = [[PLog alloc] init]; }
~HelloWorld() { [printLog release]; }
void sayHi() { printf("Hi\n"); }
void sayHello() { [printLog sayHi:this]; }
};
@implementation PLog
- (void) sayHello { NSLog(@"Hello, World!"); }
- (void) sayHi:(HelloWorld *)p { p->sayHi(); }
- (id) init { [super init]; ptr = new HelloWorld(false); return self; }
- (void) dealloc { delete ptr; [super dealloc]; }
@end
int main() {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
PLog* plog = [[PLog alloc] init];
HelloWorld* hello = new HelloWorld(true);
[plog sayHello];
hello->sayHello();
[plog sayHi:hello];
hello->sayHi();
[plog release];
delete hello;
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment