08403cb91af186a2a8830537b0a509af8217d5c2
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... :-)
9 def_interface(Animal
,Actions
)
11 str
method(talk
) (Animal self
);
20 construct(Animal
,Actions
) (Animal self
, str name
)
26 /* implementation of methods */
28 str
catTalk(Animal self
)
33 str
dogTalk(Animal self
)
38 /* registration of methods to object interface */
40 Actions
catActions(void)
42 Get_mem(this, Actions
);
48 Actions
dogActions(void)
50 Get_mem(this, Actions
);
56 /* usage of objects inside C<<1 program */
62 Actions cat
= catActions();
63 Actions dog
= dogActions();
65 animal
[0] = get_obj(Animal
, cat
, "Missy");
66 animal
[1] = get_obj(Animal
, cat
, "Mr. Bojangles");
67 animal
[2] = get_obj(Animal
, dog
, "Lassie");
71 print(animal
[i
]->name
, ":", _(talk
, animal
[i
]));
This page took 0.272094 seconds and 3 git commands to generate.