-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimal.h
42 lines (31 loc) · 804 Bytes
/
animal.h
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
#ifndef ANIMAL_H
#define ANIMAL_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "error.h"
typedef struct {
struct {
void (*speak)(void* self);
int (*delete)(void* self);
} vtable;
void* private;
char* name;
} animal_t;
int animal_new(animal_t* self, const char* type, const char* name);
int animal_delete(animal_t* self);
void animal_speak(animal_t* self);
const char* animal_getType(animal_t* self);
// Create a nice structure to expose them in :D
static const struct {
int (*new)(animal_t*, const char*, const char*);
int (*delete)(animal_t*);
void (*speak)(animal_t*);
const char* (*getType)(animal_t*);
} Animal = {
.new = &animal_new,
.delete = &animal_delete,
.speak = &animal_speak,
.getType = &animal_getType
};
#endif // ANIMAL_H