#import <Foundation/NSObject.h>
#import <stdio.h>
@interface Animal : NSObject
{
const char * name;
}
- (void) play;
@end
@implementation Animal
- (void) play {}
@end
@interface Dog : Animal
- (id) init: (const char *) name;
- (void) play;
@end
@implementation Dog
- (id) init: (const char *) value {
self = [super init];
if (self != nil) {
self->name = value;
}
return self;
}
- (void) play {
}
@end
@interface Cat : Animal
{
int sleep;
}
- (id) init: (const char *) name flag: (int) sleep;
- (void) play;
@end
@implementation Cat
- (id) init: (const char *) value flag: (int) flag {
self = [super init];
if (self != nil) {
self->name = value;
self->sleep = flag;
}
return self;
}
- (void) play {
if(sleep == 1) {
}
}
@end
int main(int argc, char *argv[]) {
int i;
id pets[] = {
[[Dog alloc] init:"ぽち"],
[[Cat alloc] init:"たま" flag:1]
};
for(i = 0; i < (sizeof(pets)/sizeof(pets[0])); i++) {
[pets[i] play];
}
for(i = 0; i < (sizeof(pets)/sizeof(pets[0])); i++) {
[pets[i] release];
}
return 0;
}
I2ltcG9ydCA8Rm91bmRhdGlvbi9OU09iamVjdC5oPgojaW1wb3J0IDxzdGRpby5oPgoKQGludGVyZmFjZSBBbmltYWwgOiBOU09iamVjdAp7CiAgICBjb25zdCBjaGFyICogbmFtZTsKfQotICh2b2lkKSBwbGF5OwpAZW5kCgpAaW1wbGVtZW50YXRpb24gQW5pbWFsCi0gKHZvaWQpIHBsYXkge30KQGVuZAoKQGludGVyZmFjZSBEb2cgOiBBbmltYWwKLSAoaWQpIGluaXQ6IChjb25zdCBjaGFyICopIG5hbWU7Ci0gKHZvaWQpIHBsYXk7CkBlbmQKCkBpbXBsZW1lbnRhdGlvbiBEb2cKLSAoaWQpIGluaXQ6IChjb25zdCBjaGFyICopIHZhbHVlIHsKICAgIHNlbGYgPSBbc3VwZXIgaW5pdF07CiAgICBpZiAoc2VsZiAhPSBuaWwpIHsKICAgICAgICBzZWxmLT5uYW1lID0gdmFsdWU7CiAgICB9CiAgICByZXR1cm4gc2VsZjsKfQotICh2b2lkKSBwbGF5IHsKICAgIHByaW50Zigi44KP44KT44KP44KT77yBJXPjgaDjgohcbiIsIG5hbWUpOwp9CkBlbmQKCkBpbnRlcmZhY2UgQ2F0IDogQW5pbWFsCnsKICAgIGludCBzbGVlcDsKfQotIChpZCkgaW5pdDogKGNvbnN0IGNoYXIgKikgbmFtZSAgZmxhZzogKGludCkgc2xlZXA7Ci0gKHZvaWQpIHBsYXk7CkBlbmQKCkBpbXBsZW1lbnRhdGlvbiBDYXQKLSAoaWQpIGluaXQ6IChjb25zdCBjaGFyICopIHZhbHVlIGZsYWc6IChpbnQpIGZsYWcgIHsKICAgIHNlbGYgPSBbc3VwZXIgaW5pdF07CiAgICBpZiAoc2VsZiAhPSBuaWwpIHsKICAgICAgICBzZWxmLT5uYW1lID0gdmFsdWU7CiAgICAgICAgc2VsZi0+c2xlZXAgPSBmbGFnOwogICAgfQogICAgcmV0dXJuIHNlbGY7Cn0KLSAodm9pZCkgcGxheSB7CiAgICBwcmludGYoIuOBq+OCg+OBgu+8gSVz44Gg44KIXG4iLCBuYW1lKTsKICAgIGlmKHNsZWVwID09IDEpIHsKICAgICAgICBwcmludGYoIi4uLuOBp+OCguWvneOCi1xuIik7CiAgICB9Cn0KQGVuZAoKCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKICAgIGludCBpOwogICAgaWQgcGV0c1tdID0gewogICAgICAgIFtbRG9nIGFsbG9jXSBpbml0OiLjgb3jgaEiXSwKICAgICAgICBbW0NhdCBhbGxvY10gaW5pdDoi44Gf44G+IiBmbGFnOjFdCiAgICB9OwoKICAgIGZvcihpID0gMDsgaSA8IChzaXplb2YocGV0cykvc2l6ZW9mKHBldHNbMF0pKTsgaSsrKSB7CiAgICAgICAgW3BldHNbaV0gcGxheV07CiAgICB9CgogICAgZm9yKGkgPSAwOyBpIDwgKHNpemVvZihwZXRzKS9zaXplb2YocGV0c1swXSkpOyBpKyspIHsKICAgICAgICBbcGV0c1tpXSByZWxlYXNlXTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==