A C-implemented polymorphism framework. It demonstrates how polymorphism works using a pure procedural programming language.
It consists of 3 demos:
-
cpp
directory contains a classic C++ polymorphism demo. It's pretty straight forward so no need to say more about it. -
c
directory contains the full C-expansion of the C++ case above. It shows how vtable is organize and managed, and how virtual function call happens, in a C fashion. -
pc
directory contains the frameworked version of the C case above. The polymorphic-c framework is actually implemented in filepolymorphic_c.h/c
andmain.c
shows how to use it.
Note this is a show-case project rather than a product. If you want to use polymorphism in your project, just choose an OOP language.
CMake
mkdir build
cd build
cmake ..
make [demo_cpp|demo_c|demo_pc]
- Class define.
- Inheritance.
- User-defined ctor and dtor.
- Virtual function define/override.
See pc/main.c
.
- Max number of member functions in a single class is fixed.
- User-defined ctor with parameters is not supported yet.
- Function overload, both intra and inter-class, is not supported yet.
- Access control is not supported yet.
- Multi-inheritance is not supported yet.