創建如下文件目錄 :
Shape.h
#include <stdlib.h> Interface struct Class struct SHAPE_H_ * (* (* p_shape Shape( _Shape( * /* SHAPE_H_ */
Shape.c
#include = (p_shape) malloc(->edge =->getEdge =->calcArea = _Shape( * (NULL != shape-> -
Triangle.h
#include TRIANGLE_H_ * (* (* p_triangle Triangle( bottom, _Triangle( * /* TRIANGLE_H_ */
Triangle.c
#include bottom, = (p_triangle) malloc(->bottom =->height =->super = Shape(->getEdge =->calcArea = _Triangle( * (NULL != triangle->super-> triangle->bottom * triangle->height /
Rectangle.h
#include RECTANGLE_H_ * (* (* p_rectangle Rectangle( bottom, _Rectangle( * /* RECTANGLE_H_ */
Rectangle.c
#include bottom, = (p_rectangle) malloc(->bottom =->height =->super = Shape(->getEdge =->calcArea = _Rectangle( * (NULL != rectangle->super-> rectangle->bottom * rectangle->
Main.c
#include <stdio.h> = Triangle(, , triangle->, triangle->= Rectangle(, , rectangle->, rectangle->
編譯運行,結果如下: