??C????????????????
???????????? ???????[ 2013/7/11 10:37:14 ] ????????
????????????????????????????????????????????????????????????????????? ???????? C ?ж?????????????????????????? lw_oopc.h ???????????????????????????£?
????1????????壺??????????????????????????????????????????????????????? ????????????????????????ü???????????????????????????????
/* operater.h */
#ifndef OPER_H
#define OPER_H INTERFACE(IOPERATOR)
{
double (*GetResult)(double??double)??
}??
#endif
/*-------------end of operater.h ------------------*/
????2?? ?????? Add ??????? IOPERATOR
/***** Add.C ***/
#include "lw_oopc_kc.h"
#include"operater.h" // ?????????????lw_oopc_kc.h ????????????????
#include "classes.h"
/************************** ?? Add ?????? classes.h ??
CLASS(Add)
{
IMPLEMENTS(IOPERATOR)??
}??************/
static double GetResult(double a??double b)
{
return (a+b)??
}
CTOR(Add)
FUNCTION_SETTING(IOPERATOR.GetResult??GetResult)?? END_CTOR
/***----- END OF ADD.C-----****/
????3?? ??????? Sub ??????? IOPERATOR
/***--- Sub.c ---******/
#include "lw_oopc_kc.h"
#include"operater.h"
#include "classes.h"
/***********?? Sub ?????? classes.h ??
CLASS(Sub)
{
IMPLEMENTS(IOPERATOR)??
}??*/
static double GetResult(double a??double b)
{
return (a-b)??
}
CTOR(Sub) FUNCTION_SETTING(IOPERATOR.GetResult??GetResult)??
END_CTOR
/***----- END OF Sub.C-----****/
????4?? ?????? operater.h??Add.C??Sub.C ?? main.C ???????????main.c ??????£?
/***--- main.c ---******/
#include<stdio.h>
#include "lw_oopc_kc.h"
#include"operater.h" // ?????????????lw_oopc_kc.h ?????????
#include "classes.h" int main()
{
int a = 10?? b=5??
int c1??c2??
IOPERATOR *poper?? //--???????????????????
Add A?? //---???? A ????????????
Sub S?? //---???? B ?????????????
CLASS_CTOR(Add?? A)?? CLASS_CTOR(Sub?? S)??
//---?????洦?????
poper = &A?? //?????????淽????oper = New(Add)?? ??? free????
c1 = (poper->GetResult(a??b))?? // c1 ???? = 15 ?? a+b??
poper = &S??
c2 = poper->GetResult(a??b)?? // c2 ???= 5 ??a-b??
return 0??
}
/***----- END OF main.C-----****/
???????
????1???? lw_oopc_kc.h ???????????????????????????????????????£??????????o?
#define CLASS_CTOR(Class??obj) Class##Setting(&obj) //--?????????
#define INHERIT(BASE) IMPLEMENTS(BASE) //---???к?
#ifndef LW_OOPC_PURE_STATIC
#ifndef LW_OOPC_STATIC
#define New(Class) Class##New() //--??????????
#endif
#endif
????2???????????????? 3 ???????塢?????????????????????????????????????????????????????????
????3???????????????????????????ж???????????????????????????????????и????? ???????????????У?????С?
???????????????????????????乹????????????????????????????????? ???????????????????????????????????????????????????????и??e????????????????
????5?? ?????????????д?????????????????????????????????????
????e.g. double GetResult(double a??double b) ????????????
????double ??* GetResult??(double?? double????
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11