Advertisement
Guest User

Untitled

a guest
Sep 14th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. behav MyBehav               // declaring a behaviour
  2.   {
  3.     void TestMe ()
  4.       {
  5.         printf ("Tested!\n");
  6.       }
  7.   };
  8.  
  9. float behav             // extending a primitive with a behaviour
  10.   {
  11.     behav MyBehav;          // reusing a behaviour
  12.     float Zero (float *this)
  13.       {
  14.         return (*this = 0);
  15.       }
  16.   };
  17.  
  18. struct Vector_s
  19.   {
  20.     int x, y, z;
  21.     behav MyBehav;          // reusing a behaviour
  22.     behav               // declaring an anonymous behaviour
  23.       {
  24.        void Print (struct Vector_s *);
  25.       }
  26.   };
  27.  
  28.  
  29. float x = 5;
  30. struct Vector_s v;
  31.  
  32. MyBehav.TestMe ();
  33. x.MyBehav.TestMe ();
  34. x.Zero ();
  35. float.Zero (&x);
  36. v.MyBehav.TestMe ();
  37. v.Print ();
  38. Vector_s.Print (&v);
  39.  
  40.  
  41. void Vector_s.Print (struct Vector_s *)
  42.      struct Vector_s *this;
  43.   {
  44.     printf ("%i, %i, %i\n", this->x, this->y, this->z);
  45.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement