-
Notifications
You must be signed in to change notification settings - Fork 1
/
cat.c
42 lines (35 loc) · 901 Bytes
/
cat.c
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
42
#include <stdio.h>
#include <string.h>
#include "animal.h"
#include "cat.h"
/* private methods */
static void cat_food(struct cat_s const *cato);
static void cat_meow(struct cat_s const *cato);
static void cat_food(struct cat_s const *cato)
{
printf("[%s] eats cat food\n", cato->animal.name);
}
static void cat_meow(struct cat_s const *cato)
{
printf("[%s] says meeoww!\n", cato->animal.name);
}
/* public methods */
int cat_age(struct cat_s *cato)
{
return cato->age;
}
int cat_weight(struct cat_s *cato)
{
return cato->weight;
}
/* Cat constructor */
void cat_ctor(struct cat_s *cato, char *name, int age, int weight)
{
/* call superclass constructor */
animal_ctor(&cato->animal, name);
/* initialize subclass attributes / virtual functions */
static struct animal_vtab_s const vtbl = {&cat_food, &cat_meow};
cato->animal.vptr = &vtbl;
cato->age = age;
cato->weight = weight;
}