is this how you guys would create a "class" in C? How about an interface? I’m guessing we just use function pointers for everything and we can change where the function pointers point to?
#ifndef CLASS
#define CLASS
void method1() { printf("method #1"); }
void method2() { printf("method #2"); }
typedef struct {
void (*method1)(void);
void (*method2)(void);
} Class;
Class class;
void class_setup()
{
class.method1 = &method1;
class.method2 = &method2;
}
#endif
int main()
{
class_setup();
class.method1();
class.method2();
return 0;
}
You need to sign in to view this answers