3 /* This is C<<1 rewrite of object polymorphism from
4 http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming */
10 Animal
method(init
) (Animal self
, str name
);
11 str
method(talk
) (Animal self
);
20 str
cat_talk(Animal self
)
25 str
dog_talk(Animal self
)
30 Animal
animal_init(Animal self
, str name
)
36 Actions
cat_actions(Actions
this)
38 this->init
= animal_init
;
39 this->talk
= cat_talk
;
42 Actions
dog_actions(Actions
this)
44 this->init
= animal_init
;
45 this->talk
= dog_talk
;
52 Actions cat
= cat_actions();
53 Actions dog
= dog_actions();
55 animal
[0] = init_obj(Animal
, Actions
, cat
)
57 animal
[1] = init_obj(Animal
, cat
, "Mr. Bojangles");
58 animal
[2] = init_obj(Animal
, dog
, "Lassie");
62 printf("%s: %s\n", animal
[i
].name
, _(talk
, animal
[i
]));
This page took 0.365559 seconds and 4 git commands to generate.