摘要:
C语言并不支持类这样的概念,但是C仍旧可以使用面向对象的概念。C++中的类,关键在于它的虚函数表。因此,我们要模拟一个能够支持虚函数表的类。使用C的struct结构,可以模拟类和虚函数。比如,我们来模拟一个shape类[cpp]view plaincopy//模拟虚函数表typedefstruct_ShapeShape;structShapeClass{void(*construct)(Shape*self);void(*destroy)(Shape*self);void(*draw)(Shape*self);};struct_Shape{ShapeClass*klass;//定义class的 阅读全文
posted @ 2014-02-13 11:00
Bonker
阅读(469)
评论(0)
推荐(1)

浙公网安备 33010602011771号