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/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 C/OOP/main.c (limited to 'C/OOP/main.c') diff --git a/C/OOP/main.c b/C/OOP/main.c new file mode 100644 index 0000000..7943580 --- /dev/null +++ b/C/OOP/main.c @@ -0,0 +1,30 @@ +/* + * Simple program exemplifying the usage of Animal class + * and its sub-classes + */ +#include + +/* + * The main program here, only need access to the public interfaces + * but the sub-classes will need access to the animal's private interface + */ +#include "animal_p.h" +#include "cat_p.h" + +int main(void) { + + /* We don't need to know how the cat object is implemented */ + struct cat *myCat = cat_new(); + + cat_ctor(myCat); + + /* + * For us to have the Animal class definition hidden, the animal_sound() + * should have a way to defer the parent Animal class, from the cat class. + * + * See its implementation within animal.c + */ + animal_sound((struct animal *)myCat); + return 0; +} + -- cgit v1.2.3