3 /* This is C<<1 rewrite of object polymorphism from
4 http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming */
8 use_interface(AnimalActions
);
14 const char *(method(talk
));
17 struct *Animal
get_animal(char *name
, struct AnimalActions
*interface
)
19 struct *Animal animal
=get_object(Animal
,interface
);
24 const char *cat_talk(void *_self
)
29 const char *dog_talk(void *_self
)
34 interface_implementation(CatActions
,AnimalActions
)
36 bind_method(talk
,cat_talk
);
39 interface_implementation(DogActions
,AnimalActions
)
41 bind_method(talk
,dog_talk
);
47 struct Animals
*animal
[3];
48 struct AnimalActions
*cat
= get_interface(CatActions
);
49 struct AnimalActions
*dog
= get_interface(DogActions
);
51 animal
[0]=get_animal("Missy",cat
);
52 animal
[0]=get_animal("Mr. Bojangles",cat
);
53 animal
[0]=get_animal("Lassie",dog
);
56 printf("%s: %s\n",animal
[i
].name
,(_(animal
[i
],talk
)));
This page took 0.660894 seconds and 4 git commands to generate.