Objective-Cおもしれえわ
ちょっと息抜きにObjective-Cを勉強。(本当にまだ序章
で、出てきたプログラム
#import <Foundation/NSObject.h> #import <stdio.h> @interface A : NSObject - (void)whoAreYou; @end @implementation A - (void)whoAreYou { printf("I'm A.\n"); } @end @interface B : A - (void)whoAreYou; - (void)sayHello; @end @implementation B - (void)whoAreYou { printf("I'm B.\n"); } - (void)sayHello { printf("Hello.\n"); } @end @interface C : NSObject - (void)printName; @end @implementation C - (void)printName { printf("I'm C.\n"); } @end int main(void) { A* a; A* b; C* c; a = [[A alloc] init]; b = [[B alloc] init]; c = [[C alloc] init]; [a whoAreYou]; [b whoAreYou]; [c printName]; return 0; }
うっはw
しかも動的結合があるので、
[c whoAreYou];
と書いても
'C' may not respond to '-whoAreYou'
とwarningで済まされる。(実行時にエラーになります)
これ格好いいわー。
Sconsでコンパイルしているので、
Program(['test.m'],LINKFLAGS="-framework Foundation")
でコンパイルできます。
OSXでです、勿論。