Aleks11

R/L values

Dec 22nd, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <conio.h>  // _getch();
  2. #include <stdio.h>
  3. #include <memory.h>
  4. #include <algorithm>
  5.  
  6. struct IntObj
  7. {
  8.     IntObj(int _a)
  9.     {
  10.         a = new int;
  11.         *a = _a;
  12.     }
  13.     int *a;
  14. };
  15.  
  16. IntObj myA(0);
  17.  
  18. void func(IntObj &a)
  19. {
  20.     *myA.a = *a.a;
  21.     printf("Copying data\n");
  22. }
  23.  
  24. void func(IntObj &&a)
  25. {
  26.     myA.a = a.a;
  27.     a.a = NULL;
  28.     printf("Moving data\n");
  29. }
  30.  
  31. int main()
  32. {
  33.     func(IntObj(20));
  34.     printf("%d\n", *myA.a);
  35.  
  36.     IntObj ar(30);
  37.     func(ar);
  38.     printf("%d\n", *myA.a);
  39.  
  40.     _getch();
  41.     return 0;
  42. }
  43.  
  44. /*
  45.  
  46. Moving data
  47. 20
  48. Copying data
  49. 30
  50.  
  51. */
Advertisement
Add Comment
Please, Sign In to add comment