Created
June 1, 2009 11:49
-
-
Save akio0911/121363 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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