prev up next   top/contents search

comp.lang.c FAQ list · Question 2.4b

Q: Is there a good way of simulating OOP-style inheritance, or other OOP features, in C?


A: It's straightforward to implement simple ``methods'' by placing function pointers in structures. You can make various clumsy, brute-force attempts at inheritance using the preprocessor or by having structures contain ``base types'' as initial subsets, but it won't be perfect. There's obviously no operator overloading, and overriding (i.e. of ``methods'' in ``derived classes'') would have to be done by hand.

Obviously, if you need ``real'' OOP, you'll want to use a language that supports it, such as C++.

Additional links: An article by James Hu exploring some possibilities in more detail.


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North