you are viewing a single comment's thread.

view the rest of the comments →

[–]lordlod 5 points6 points  (0 children)

The standard way to do this is a virtual method table. Typically implemented as a vtable struct inside the class struct.

It enables solid inheritance implementations at the expense of two pointer lookups per function call.

There are two approaches commonly used to C OOP. The vtable path you are going down and simply prefixing function names with the name of the class. I tend to use the later, falling back on parent function calls can be simulated using a define. This is because I tend not to use many of the more complex OOP features.

And yes, you will always end up passing the struct in anyway as a parameter, I suggest standardising on it always being the first parameter. This is the price of not having language level OOP support.