Example of Object-Oriented C
Matthew J. Miller (matt@matthewjmiller.net)


This gives an idea of how aspects of object-oriented programming can be implmented in C. It particular, it demonstrates multiple inheritance, an abstract class, and multiple levels of inheritance. Opaque pointers are used to completely encapsulate a class's virtual function table so it is inaccessible directly even to friend classes.

It and of itself, this isn't particularly useful because there is so much manual work to setup basic OO-relations. This is more of a playground to try stuff for which a code generator could then be built to automate the code for these relationships.

base1 and base2 are base classes. base2 is an abstract class that has a pure virtual function (base2_increase_val1()). derived1 inherits from both base1 and base2. derived2 inherits from derived1.

The files follow the convention:


Just run make and the test_c_oo test program will be run. You can edit test_c_oo.c to try various things with this class hierarchy. Running make clean will remove the executable and .o files.

GNU General Public License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines