@@ -56,6 +56,7 @@ inline Apple * Constructor_Apple(Apple * __this)
5656
5757inline void Destructor_Apple(Apple * __this)
5858{
59+ __this->__vptrFruit = __vtbl_array[1];
5960 (*((void (*)(const Apple *))((__this)->__vptrFruit[1]).f))((((const Apple *)(char *)(__this)) + ((__this)->__vptrFruit[1]).d));
6061 Destructor_Fruit((Fruit *)__this);
6162}
@@ -66,12 +67,37 @@ inline void PrintApple(const Apple * __this)
6667}
6768
6869
70+ typedef struct Orange
71+ {
72+ __mptr * __vptrFruit;
73+ } Orange;
74+
75+ inline Orange * Constructor_Orange(Orange * __this)
76+ {
77+ Constructor_Apple((Apple *)__this);
78+ __this->__vptrFruit = __vtbl_array[2];
79+ return __this;
80+ }
81+
82+ inline void Destructor_Orange(Orange * __this)
83+ {
84+ __this->__vptrFruit = __vtbl_array[2];
85+ (*((void (*)(const Orange *))((__this)->__vptrFruit[1]).f))((((const Orange *)(char *)(__this)) + ((__this)->__vptrFruit[1]).d));
86+ Destructor_Apple((Apple *)__this);
87+ }
88+
89+ inline void PrintOrange(const Orange * __this)
90+ {
91+ puts("Orange");
92+ }
93+
94+
6995int __main(void)
7096{
71- Apple x;
72- Constructor_Apple((Apple *)&x);
97+ Orange x;
98+ Constructor_Orange((Orange *)&x);
7399 return 0;
74- (*((void (*)(Apple *))((&x)->__vptrFruit[0]).f))((((Apple *)(char *)(&x)) + ((&x)->__vptrFruit[0]).d));
100+ (*((void (*)(Orange *))((&x)->__vptrFruit[0]).f))((((Orange *)(char *)(&x)) + ((&x)->__vptrFruit[0]).d));
75101}
76102
77103int main(void)
@@ -85,8 +111,9 @@ int main(void)
85111
86112__mptr __vtbl_Fruit[2] = {{0, 0, (__vptp)Destructor_Fruit}, {0, 0, (__vptp)PrintFruit}};
87113__mptr __vtbl_Apple[2] = {{0, 0, (__vptp)Destructor_Apple}, {0, 0, (__vptp)PrintApple}};
114+ __mptr __vtbl_Orange[2] = {{0, 0, (__vptp)Destructor_Orange}, {0, 0, (__vptp)PrintOrange}};
88115
89- __mptr * __vtbl_array[2 ] = {__vtbl_Fruit, __vtbl_Apple};
116+ __mptr * __vtbl_array[3 ] = {__vtbl_Fruit, __vtbl_Apple, __vtbl_Orange };
90117
91118void __cxa_start(void)
92119{
0 commit comments