??C????????????????
???????????? ???????[ 2013/7/11 10:37:14 ] ????????
?????????????????????????????????????????????μ???
????1???????壬???? CLASS() ?? lw_oopc_kc.h ?ж?????
#include "lw_oopc_kc.h"
CLASS(A)
{
int a?? void(*init)(void*??int)?? void(*put)(void*)??
}??
????2??????????????
???????????????y??? struct ???壬?ú??????????? C++??????????????????????????????? A ?????д??庯????
void init_A(void *t??int x)
{
A *cthis = (A*)t??
cthis->a = x??
}
void put_A(void*t)
{
A *cthis = (A*)t??
printf(" %d "??cthis->a)??
}
????3???????壩?е???????????????????? ???????????????????????????????????????
CTOR(A)
FUNCTION_SETTING (init?? init_A)?? FUNCTION_SETTING (put?? put_A)??
END_CTOR
????4?????????塢?????????
???????????????????????????? struct???е?????????к????????????? init_A()?? XXX_A() ??????????????? XXX_A()???? A ???????????????????????????????????? ???? C++?????????????????ù??????????? C ?У????????????????????????????? lw_oopc_kc.h ????"lw_oopc.h"?????????ú?CLASS_CTOR(class??obj)??????????????й????? ??????????з????????????????????? 3 ???????£?
A aa1?? // 1?????????
CLASS_CTOR(A??aa1)?? // 2?????????—??ú??????????????
aa1.init(&aa1?? 10)?? // 3?????????????????????????? &aa1????????
????????C ??е?????
????1?????????壺???????????????????????ж??????????????????????????????У???????????壺
????#define INHERIT(BASE) IMPLEMENTS(BASE)
???????????? B ????? A ????????£?
CLASS(B)
{
INHERIT(A)?? // ??? A ?? int b?? // ??????? void (*init) (void*?? int x)??
void (*put) (void*)??
}??
????2??????????????????????????? B ????????????? ‘_B’
void init_B (void*t?? int x?? int y)
{
B *cthis = (B*) t??
CLASS_CTOR(A?? cthis->A)?? //----??е?????????????????? cthis->A cthis->A.init(&cthis->A?? x)?? //----??е??????????? ???&cthis->A cthis->b = y??
}
void put_B (void *t)
{
B *cthis = (B*) t??
cthis->A.put (&cthis->A)?? //---?????????????
printf(" %d "??cthis->b)?? //---????????
}
????3????????????????????????????????????????????
????CTOR(B)
????FUNCTION_SETTING (init?? init_B)?? //---??????????????????
????FUNCTION_SETTING (put?? put_B)?? END_CTOR
????????????????????????????????? CTOR(B) ?? END_CTOR ?????У????????????? B ?????????????????????CLASS_CTOR(A?? cthis->A)????????????棬??÷??? init_B() ???????棬???????? B ??????????????????????????????? C++?????????????C++????? B ????????????? A ??????????????????е????????????main()?????????????
int main()
{
A aa1?? B b??
CLASS_CTOR(A??aa1)?? //--???? aa1 ???? aa1.init(&aa1??5)?? //--????? aa1 ????aa1.put(&aa1)?? //--???? aa1 ???????????
CLASS_CTOR(B?? b)?? //---???? b ????
b.init(&b??100??78)?? //--????? b ???????????? A ??????????
b.put(&b)?? //--???? b ??????????
b.A.put(&b.A)?? //--???? b ??????????????
return 0??
??
?????????????5 100 78 100
??????
???·???
??????????????????
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