// Struct With Multiple Function Pointers
// “Methods” That Take the Struct Itself (OOP in C)
#include <stdio.h>
typedef struct Object {
int x;
void (*set)(struct Object*, int);
void (*print)(struct Object*);
} Object;
void setX(Object* self, int v) {
self->x = v;
}
void printX(Object* self) {
printf("x = %d\n", self->x);
}
int main() {
Object obj = { 10, setX, printX };
obj.print(&obj);
obj.set(&obj, 99);
obj.print(&obj);
return 0;
}
/*
run:
x = 10
x = 99
*/