8b6251af9462fe808ff53cf493eee8a6a08b4158
3 /* This is C<<1 rewrite of object polymorphism from
4 http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming
6 Of course there are easier ways to do the same thing... :-)
13 str
method(talk
) (Animal self
);
22 construct(Animal
,Actions
) (Animal self
, str name
)
28 /* implementation of methods */
30 str
catTalk(Animal self
)
35 str
dogTalk(Animal self
)
40 /* registration of methods to object interface */
42 Actions
catActions(void)
44 Get_mem(this, Actions
);
50 Actions
dogActions(void)
52 Get_mem(this, Actions
);
58 /* usage of objects inside C<<1 program */
64 Actions cat
= catActions();
65 Actions dog
= dogActions();
67 animal
[0] = get_obj(Animal
, cat
, "Missy");
68 animal
[1] = get_obj(Animal
, cat
, "Mr. Bojangles");
69 animal
[2] = get_obj(Animal
, dog
, "Lassie");
73 print(animal
[i
]->name
, ":", _(talk
, animal
[i
]));
This page took 0.343656 seconds and 3 git commands to generate.