OODuck
0.5
C Oriented Object framework with duck-typing support
|
This tutorial will teach you how to use OODuck and how to create custom Class.
In order to use the OODuck dynamic typing, you need the following skeleton:
Class are defined in their own header, which must be included to use them:
All objects and classes are stored in a pointer, hiding implementation:
Methods are accessed dynamically, and their prototype is defined with the help of typedef
:
NB: the methods prototypes are located in the class header (here: ooduck/string.h
).
Finally, an object is freed with the delete()
function:
All objects (Class included) have a reference counter initialized to 1
. When this counter equals 0
, the object is automatically deleted:
The first step is to define our Class structure:
A Class is an Object, like everything else, then we can create it with new()
using the macro OODUCK_DEFINE_CLASS
which handles thread-safety:
In the header, we must add the declaration using the macro OODUCK_DECLARE_CLASS
, allowing us to call MyClass ()
:
Now, we can proceed to implementation:
The last step is to define prototypes for our methods:
Finally, we can use our new class: