Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- using namespace std;
- void decrement(unique_ptr<int> &n);
- unique_ptr<int> increment(unique_ptr<int> n);
- int
- main()
- {
- unique_ptr<int> n(new int(10));
- cout << "*n = " << *n << endl;
- decrement(n);
- cout << "*n = " << *n << endl;
- n = std::move(increment(std::move(n)));
- cout << "*n = " << *n << endl;
- return 0;
- // n will die here
- }
- void
- decrement(unique_ptr<int> &n)
- {
- --(*n);
- }
- unique_ptr<int>
- increment(unique_ptr<int> n)
- {
- ++(*n);
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment