许多朋友都知道用C语言是可以实现面向对象程序设计的,但是具体到操作的细节部分就有些茫然不知所措了。为此作者在研究LW_OOPC的基础上,对其进行充分的简化,只保留最基本的面向对象功能,形成自己的OOSM宏包,其实这些东西已经够用了,以下是OOSM宏包的源代码:
/*
Object-Oriented Support Macros(OOSM)
OOSM is an object-oriented support macros, it makes the C programming language
with object-oriented programming capabilities.
LW_OOPC(http://sourceforge.net/projects/lwoopc/) means
Light-weight Object-Oriented Programming in C, written by MISOO team,
it is a very outstanding works!
OOSM inherits the essence of LW_OOPC and crops to retain the basic features.
OOSM written by Turingo Studio,
but anyone can copies modifies, and distributes it freely.
Hansome Sun(hansome.sun@gmail.com)
January 18, 2013
*/
#ifndef __OOSM_H__
#define __OOSM_H__
#include <stdlib.h>
#define class(type) \
typedef struct type type;

本文介绍了如何在C语言中实现面向对象编程,通过LW_OOPC的基础并简化为OOSM宏包,提供了不到30行的源代码示例,展示了C语言实现面向对象编程的低成本和优雅性。
最低0.47元/天 解锁文章





