employee.c

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

C
95
字号
/* ****************************** * 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>/*-----------------------------*//*   employee implementation   *//*-----------------------------*/#define IMPLEMENTATION#include <employee.h>/*  ---------------------  Object implementation  ---------------------*/voidconstMethodOvldDecl(print, person){  sendCMsg(this, person, print);  printf("\tdept:\t%s\n", sub_cast(this,person)->m.department);}OBJECT_IMPLEMENTATION  SUPERCLASS(person)ENDOF_IMPLEMENTATION/*  --------------------  Class implementation  --------------------*/initClassDecl() /* required */{  /* initialize super class */  initSuper(person);  /* overload super class methods */  overload(person.print) = methodOvldName(print, person);}dtorDecl() /* required */{  person._person(super(this,person));  free((void*)this->m.department);  this->m.department = NULL;}t_employeeclassMethodDecl_(*const new)     char const name[], char const department[] __{  t_employee *const this = employee.alloc();  if (this) employee.init(this, name, department);  return this;}voidmethodDecl_(init)     char const name[], char const department[] __{  person.init(super(this,person), name);  this->m.department = strdup(department);}voidmethodDecl_(copy) t_employee const*const emp __{  employee._employee(this);  employee.init(this, emp->m.person.m.name, emp->m.department);}CLASS_IMPLEMENTATION  methodName(new),  methodName(init),  methodName(copy)ENDOF_IMPLEMENTATION

⌨️ 快捷键说明

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