On Thu, Nov 27, 2014, at 07:27, koneu wrote: > Greetings. > > The two things that really make OO languages worthwhile in my opinion > are polymorphism and inheritance. Doing polymorphism and data/code > hiding in C is easy enough with const function pointers. You can just > define public interfaces in their own header like > > struct interface { > void * const this; > int (* const get_foo)(void *this); > void (* const set_foo)(void *this, int foo); > char * (* const get_bar)(void *this); > void (* const set_bar)(void *this, char *bar); > }; > > and implement them in "classes" like > > struct class { > int foo; > char *bar; > };
In general when this is done in real life, you do it the other way around, so you only need one copy of the interface structure per class.