blob: c513bb61e52bb3eb7a881ca57536afb24ac3fe73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}
|