3 /* This is C<<1 rewrite of object polymorphism from
4 http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming */
10 void method(init
) (Animal self
, str name
);
11 str
method(talk
) (Animal self
);
20 Animal
construct(Animal
) (Animal self
, str name
)
26 str
cat_talk(Animal self
)
31 str
dog_talk(Animal self
)
36 Actions
cat_actions(void)
38 Actions
this=get_mem(Actions
);
39 this->talk
= cat_talk
;
43 Actions
dog_actions(void)
45 Actions
this=get_mem(Actions
);
46 this->talk
= dog_talk
;
54 Actions cat
= cat_actions();
55 Actions dog
= dog_actions();
57 animal
[0] = get_obj(Animal
, cat
, "Missy");
58 animal
[1] = get_obj(Animal
, cat
, "Mr. Bojangles");
59 animal
[2] = get_obj(Animal
, dog
, "Lassie");
63 printf("%s: %s\n", animal
[i
]->name
, _(talk
, animal
[i
]));
This page took 0.317098 seconds and 4 git commands to generate.