From 5d6d031a3ab20d8e2b700f595777c8f642e55618 Mon Sep 17 00:00:00 2001 From: jf-home Date: Sun, 1 Sep 2024 13:36:12 +0800 Subject: [PATCH] =?UTF-8?q?C=E8=AF=AD=E8=A8=80=E5=8F=AF=E4=BB=A5=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=A4=9A=E6=80=81=EF=BC=8C=E4=BD=86=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E4=BF=9D=E8=AF=81=E5=AD=90=E7=B1=BB=E5=92=8C=E7=88=B6=E7=B1=BB?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E7=9A=84=E5=85=83=E7=B4=A0=E6=94=BE=E5=9C=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E6=9C=80=E5=89=8D=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E4=B8=94=E5=BF=85=E9=A1=BB=E4=B8=80=E6=A8=A1=E4=B8=80=E6=A0=B7?= =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=BA=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 1ae8b88..6c15aab 100644 --- a/main.c +++ b/main.c @@ -41,19 +41,19 @@ struct _virtual_table *virtual_new(void) struct _shape { - struct _virtual_table *vtb; + struct _virtual_table vtb; }; void shape_area(void *self) { struct _shape *pthis = (struct _shape *)self; - pthis->vtb->area(self); + pthis->vtb.area(self); } void shape_draw(void *self) { struct _shape *pthis = (struct _shape *)self; - pthis->vtb->draw(self); + pthis->vtb.draw(self); } PRIVATE void _shape_area(void *self) @@ -77,12 +77,10 @@ struct _shape *shape_new(void) .area = (void (*)(void *self))_shape_area, .draw = (void (*)(void *self))_shape_draw }; - shape->vtb = &vtb; + shape->vtb = vtb; return shape; } -#define SUPER(self) (&(self)->shape) - #if 0 void shape_free(struct _shape * self) { @@ -96,7 +94,8 @@ void shape_free(struct _shape * self) struct _rect { // super - struct _shape shape; + // struct _shape shape; + struct _virtual_table vtb; // attribute double width, height; @@ -131,14 +130,15 @@ struct _rect *rect_new(double width, double height) .draw = (void (*)(void *self))rect_draw }; - SUPER(rect)->vtb = &vtb; + rect->vtb = vtb; return rect; } struct _circle { // super - struct _shape shape; + // struct _shape shape; + struct _virtual_table vtb; // attribute double radius; @@ -171,7 +171,7 @@ struct _circle *circle_new(double radius) .draw = (void (*)(void *self))circle_draw, }; - SUPER(circle)->vtb = &vtb; + circle->vtb = vtb; return circle; }