@@ -26,10 +26,16 @@ typedef struct Fruit
2626inline Fruit * Constructor_Fruit(Fruit * __this)
2727{
2828 __this->__vptrFruit = __vtbl_array[0];
29- (*((void (*)(const Fruit *))((__this)->__vptrFruit[0 ]).f))((((const Fruit *)(char *)(__this)) + ((__this)->__vptrFruit[0 ]).d));
29+ (*((void (*)(const Fruit *))((__this)->__vptrFruit[1 ]).f))((((const Fruit *)(char *)(__this)) + ((__this)->__vptrFruit[1 ]).d));
3030 return __this;
3131}
3232
33+ inline void Destructor_Fruit(Fruit * __this)
34+ {
35+ __this->__vptrFruit = __vtbl_array[0];
36+ (*((void (*)(const Fruit *))((__this)->__vptrFruit[1]).f))((((const Fruit *)(char *)(__this)) + ((__this)->__vptrFruit[1]).d));
37+ }
38+
3339inline void PrintFruit(const Fruit * __this)
3440{
3541 puts("Base");
@@ -48,6 +54,12 @@ inline Apple * Constructor_Apple(Apple * __this)
4854 return __this;
4955}
5056
57+ inline void Destructor_Apple(Apple * __this)
58+ {
59+ (*((void (*)(const Apple *))((__this)->__vptrFruit[1]).f))((((const Apple *)(char *)(__this)) + ((__this)->__vptrFruit[1]).d));
60+ Destructor_Fruit((Fruit *)__this);
61+ }
62+
5163inline void PrintApple(const Apple * __this)
5264{
5365 puts("Apple");
@@ -59,7 +71,7 @@ int __main(void)
5971 Apple x;
6072 Constructor_Apple((Apple *)&x);
6173 return 0;
62- /* x // lifetime ends here */
74+ (*((void (*)(Apple *))((&x)->__vptrFruit[0]).f))((((Apple *)(char *)(&x)) + ((&x)->__vptrFruit[0]).d));
6375}
6476
6577int main(void)
@@ -71,8 +83,8 @@ int main(void)
7183 /* ret // lifetime ends here */
7284}
7385
74- __mptr __vtbl_Fruit[1 ] = {0, 0, (__vptp)PrintFruit};
75- __mptr __vtbl_Apple[1 ] = {0, 0, (__vptp)PrintApple};
86+ __mptr __vtbl_Fruit[2 ] = {{ 0, 0, (__vptp)Destructor_Fruit}, {0, 0, (__vptp) PrintFruit} };
87+ __mptr __vtbl_Apple[2 ] = {{ 0, 0, (__vptp)Destructor_Apple}, {0, 0, (__vptp) PrintApple} };
7688
7789__mptr * __vtbl_array[2] = {__vtbl_Fruit, __vtbl_Apple};
7890
0 commit comments