Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. class A
  4. {
  5. public:
  6. virtual void A1() { printf("A1n"); }
  7. int a2;
  8. };
  9.  
  10. class B
  11. {
  12. public:
  13. virtual void B1() { printf("B1n"); }
  14. int b2;
  15. };
  16.  
  17. class C : public A, public B
  18. {
  19. public:
  20. virtual void C1() { printf("C1n"); }
  21. int c2;
  22. };
  23.  
  24. class D : public C
  25. {
  26. public:
  27. virtual void D1() { printf("D1n"); }
  28. int d2;
  29. };
  30.  
  31. C *c;
  32. D *d;
  33.  
  34. int main()
  35. {
  36. c->A1();
  37. c->B1();
  38. c->C1();
  39.  
  40. d->A1();
  41. d->B1();
  42. d->C1();
  43. d->D1();
  44. printf("%d%d%d%d%d%d%dn", c->a2, c->b2, c->c2, d->a2, d->b2, d->c2, d->d2);
  45. return 0;
  46. }
  47.  
  48. int __cdecl main()
  49. {
  50. char v1; // [sp+Ch] [bp-C0h]@1
  51.  
  52. memset(&v1, 0xCCu, 0xC0u);
  53. c->vfptr->A1((A *)c);
  54. c->vfptr->B1(&c->vfptr);
  55. c->vfptr[1].A1((A *)c);
  56. d->vfptr->A1((A *)d);
  57. d->vfptr->B1(&d->vfptr);
  58. d->vfptr[1].A1((A *)d);
  59. d->vfptr[2].A1((A *)d);
  60. _printf("%d%d%d%d%d%d%dn", c->a2, c->b2, c->c2, d->a2, d->b2, d->c2, d->d2);
  61. return 0;
  62. }
  63.  
  64. struct A
  65. {
  66. AVtbl *vfptr;
  67. int a2;
  68. };
  69.  
  70. struct AVtbl
  71. {
  72. void (__thiscall *A1)(A *this);
  73. };
  74.  
  75. struct B
  76. {
  77. BVtbl *vfptr;
  78. int b2;
  79. };
  80.  
  81. struct BVtbl
  82. {
  83. void (__thiscall *B1)(B *this);
  84. };
  85.  
  86. struct __cppobj C : A, B
  87. {
  88. int c2;
  89. };
  90.  
  91. struct __cppobj D : C
  92. {
  93. int d2;
  94. };
  95.  
  96. struct A
  97. {
  98. AVtbl *vfptr;
  99. ABody body;
  100. };
  101.  
  102. struct ABody
  103. {
  104. int a2;
  105. };
  106.  
  107. struct AVtbl
  108. {
  109. void (__thiscall *A1)(A *this);
  110. };
  111.  
  112.  
  113. struct B
  114. {
  115. BVtbl *vfptr;
  116. BBody body;
  117. };
  118.  
  119. struct BBody
  120. {
  121. int b2;
  122. };
  123.  
  124. struct BVtbl
  125. {
  126. void (__thiscall *B1)(B *this);
  127. };
  128.  
  129.  
  130. struct C
  131. {
  132. CVtbl *vfptr;
  133. CBody body;
  134. };
  135.  
  136. struct __cppobj CBody : ABody
  137. {
  138. BVtbl *vfptr_1;
  139. BBody baseclass_1;
  140. int c2;
  141. };
  142.  
  143. struct __cppobj CVtbl : AVtbl
  144. {
  145. void (__thiscall *C1)(C *this);
  146. };
  147.  
  148.  
  149. struct D
  150. {
  151. DVtbl *vfptr;
  152. DBody body;
  153. };
  154.  
  155. struct __cppobj DBody : CBody
  156. {
  157. int d2;
  158. };
  159.  
  160. struct __cppobj DVtbl : CVtbl
  161. {
  162. void (__thiscall *D1)(D *this);
  163. };
  164.  
  165. int __cdecl main()
  166. {
  167. char v1; // [sp+Ch] [bp-C0h]@1
  168.  
  169. memset(&v1, 0xCCu, 0xC0u);
  170. c->vfptr->A1((A *)c);
  171. c->body.vfptr_1->B1(&c->body.vfptr_1);
  172. c->vfptr->C1(c);
  173. d->vfptr->A1((A *)d);
  174. d->body.vfptr_1->B1(&d->body.vfptr_1);
  175. d->vfptr->C1((C *)d);
  176. d->vfptr->D1(d);
  177. _printf(
  178. "%d%d%d%d%d%d%dn",
  179. c->body.a2,
  180. c->body.baseclass_1.b2,
  181. c->body.c2,
  182. d->body.a2,
  183. d->body.baseclass_1.b2,
  184. d->body.c2,
  185. d->body.d2);
  186. return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement