/* ****************************** * Object Oriented Programming in C * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * For more information, please see the paper: * http://home.cern.ch/ldeniau/html/oopc/oopc.html * ****************************** */ #include /*---------------------------*/ /* person implementation */ /*---------------------------*/ #define IMPLEMENTATION #include /* --------------------- Object implementation --------------------- */ void constMethodDecl(print) { printf("name:\t%s\n", this->m.name); } BASEOBJECT_IMPLEMENTATION methodName(print) ENDOF_IMPLEMENTATION /* -------------------- Class implementation -------------------- */ initClassDecl() {} /* required */ dtorDecl() /* required */ { free((void*)this->m.name); this->m.name = NULL; } t_person classMethodDecl_(*const new) char const name[] __ { t_person *const this = person.alloc(); if (this) person.init(this, name); return this; } void methodDecl_(init) char const name[] __ { this->m.name = strdup(name); } void methodDecl_(copy) t_person const*const per __ { person._person(this); person.init(this, per->m.name); } CLASS_IMPLEMENTATION methodName(new), methodName(init), methodName(copy) ENDOF_IMPLEMENTATION