Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h> // _getch();
- #include <stdio.h>
- #include <memory.h>
- #include <algorithm>
- struct IntObj
- {
- IntObj(int _a)
- {
- a = new int;
- *a = _a;
- }
- int *a;
- };
- IntObj myA(0);
- void func(IntObj &a)
- {
- *myA.a = *a.a;
- printf("Copying data\n");
- }
- void func(IntObj &&a)
- {
- myA.a = a.a;
- a.a = NULL;
- printf("Moving data\n");
- }
- int main()
- {
- func(IntObj(20));
- printf("%d\n", *myA.a);
- IntObj ar(30);
- func(ar);
- printf("%d\n", *myA.a);
- _getch();
- return 0;
- }
- /*
- Moving data
- 20
- Copying data
- 30
- */
Advertisement
Add Comment
Please, Sign In to add comment