程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 純C實現面向對象之接口編程

純C實現面向對象之接口編程

編輯:關於C語言

創建如下文件目錄 :

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-> 

編譯運行,結果如下:



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved