Advertisement
Xeeynamo

struct's properties obfuscation

Feb 18th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Texture
  4. {
  5.     int GetWidth() const;
  6.     int GetHeight() const;
  7. };
  8. struct _Texture
  9. {
  10.     int width;
  11.     int height;
  12.     _Texture()
  13.     {
  14.         printf("ctor %p\n", this);
  15.     }
  16.     ~_Texture()
  17.     {
  18.         printf("dtor %p\n", this);
  19.     }
  20. };
  21. int Texture::GetWidth() const
  22. {
  23.     return ((_Texture*)this)->width;
  24. }
  25. int Texture::GetHeight() const
  26. {
  27.     return ((_Texture*)this)->height;
  28. }
  29.  
  30.  
  31. Texture* CreateTexture(int width, int height)
  32. {
  33.     _Texture* t = new _Texture;
  34.     t->width = width;
  35.     t->height = height;
  36.     return (Texture*)t;
  37. }
  38. void DeleteTexture(Texture* texture)
  39. {
  40.     _Texture* t = (_Texture*)texture;
  41.     delete t;
  42. }
  43.  
  44. int main()
  45. {
  46.     Texture* t = CreateTexture(320, 240);
  47.     printf("%i x %i\n", t->GetWidth(), t->GetHeight());
  48.     DeleteTexture(t);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement