blob: eb5e3998320fb980a9b060f43f57d199430040c3 (
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
|
#include <stdlib.h>
#include "shape.h"
struct shape
{
void *obj;
shape_area_t area;
shape_destroy_t destroy;
};
double shape_area(struct shape *shape)
{
return shape->area(shape->obj);
}
void shape_destroy(struct shape *shape)
{
shape->destroy(shape->obj);
free(shape);
}
struct shape *shape_create(
void *obj,
shape_area_t area,
shape_destroy_t destroy)
{
struct shape *shape = malloc(sizeof(shape));
shape->obj = obj;
shape->area = area;
shape->destroy = destroy;
return shape;
}
|