person.c

来自「c语言是面向过程的程序语言」· C语言 代码 · 共 83 行

C
83
字号
/* ****************************** * 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 <stdio.h>/*---------------------------*//*   person implementation   *//*---------------------------*/#define IMPLEMENTATION#include <person.h>/*  ---------------------  Object implementation  ---------------------*/voidconstMethodDecl(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_personclassMethodDecl_(*const new) char const name[] __{  t_person *const this = person.alloc();  if (this) person.init(this, name);  return this;}voidmethodDecl_(init) char const name[] __{  this->m.name = strdup(name);}voidmethodDecl_(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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?