From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- C/OOP/cat/cat.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 C/OOP/cat/cat.c (limited to 'C/OOP/cat/cat.c') diff --git a/C/OOP/cat/cat.c b/C/OOP/cat/cat.c new file mode 100644 index 0000000..c513bb6 --- /dev/null +++ b/C/OOP/cat/cat.c @@ -0,0 +1,41 @@ +/* + * Cat class. + * + * This is a subclass of the animal class + */ + +#include +#include + +#include "animal_priv.h" +#include "animal_p.h" + +/* + * We need access to animal's definition, so we can embbed it + * within our sub-class + */ +struct cat { + struct animal animal; +}; + +void __cat_sound(void) +{ + printf("The cat makes MEOOOOOW\n"); +} + +struct cat *cat_new(void) +{ + return (struct cat*)malloc(sizeof(struct cat)); +} + +void cat_ctor(struct cat *cat) +{ + animal_ctor((struct animal *)cat, + __cat_sound); + printf("cat_ctor: cat: %p animal: %p\n", cat, &cat->animal); +} + +void cat_dtor(struct cat *cat) +{ + animal_dtor((struct animal *)cat); +} -- cgit v1.2.3