objects

objects in c
git clone https://noulin.net/git/objects.git
Log | Files | Refs | README | LICENSE

commit 2dd44d62d3c67bb10ef7c55fd9df654192ee002c
parent 905864d9cc2dabc9f7465dcf8c0cae9a8fed8ed9
Author: Remy Noulin (Spartatek) <remy.noulin@spartatek.se>
Date:   Tue, 28 Feb 2017 15:06:06 +0100

inheritance concept

main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Diffstat:
Mmain.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c @@ -11,15 +11,18 @@ // Class: base typedef struct base baset; +typedef void (*basePrintt)(baset *self, char *string); + struct base { const char *type; + basePrintt print; }; // Class: class typedef struct class classt; static const char classtName[] = "class"; -typedef void (*printt)(classt *self, char *string); +typedef void (*classPrintt)(classt *self, char *string); typedef void (*freeClasstt)(classt *self); typedef void (*terminateClasstt)(classt **self); typedef classt* (*duplicateClasstt)(classt **self); @@ -27,11 +30,11 @@ typedef classt* (*duplicateClasstt)(classt **self); struct class { // base class const char *type; + classPrintt print; // base class end int a; char *s; - printt print; terminateClasstt terminate; duplicateClasstt duplicate; freeClasstt free; @@ -122,6 +125,7 @@ void main() { baset *o; o = (baset *) unObj; printf("\nObject type: %s\n", o->type); + o->print(o, "\nOBJ UNKNOWN\n"); if (isOType(unObj, classtName)) { printf("Object type: %s\n", ((baset *) unObj)->type);