Advertisement
Xeeynamo

C++ madness

Feb 6th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. class I
  4. {
  5. public:
  6.     virtual void Release() = 0;
  7. };
  8. class A : public I
  9. {
  10. public:
  11.     void Release()
  12.     {
  13.         printf("A::Release()\n");
  14.         delete this;
  15.     }
  16. };
  17.  
  18. class Test : public I
  19. {
  20.     I* i;
  21.     void* p;
  22. public:
  23.     Test(I* i) : i(i)
  24.     {
  25.         p = *(void**)i;
  26.     }
  27.     void Release()
  28.     {
  29.         printf("Custom release\n");
  30.         *(void**)i = p;
  31.         i->Release();
  32.         delete this;
  33.     }
  34. };
  35.  
  36. template <class T>
  37. I* Create()
  38. {
  39.     return new Test(new T);
  40. }
  41.  
  42. int main()
  43. {
  44.     Create<A>()->Release();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement