summaryrefslogtreecommitdiff
path: root/C/OOP/cat
diff options
context:
space:
mode:
Diffstat (limited to 'C/OOP/cat')
-rw-r--r--C/OOP/cat/cat.c41
1 files changed, 41 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+#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);
+}