Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- #include <memory>
- unsigned int counter = 1;
- class Stuff {
- private:
- unsigned int y;
- public:
- Stuff(unsigned int x) {
- y = x * x;
- }
- };
- class A {
- public:
- int id;
- A() {
- id = counter++;
- ptr = std::make_unique<Stuff>(id);
- };
- std::unique_ptr<Stuff>& get_data() {
- return ptr;
- }
- A(A&& to_move) {
- id = to_move.id;
- ptr = std::move(to_move.get_data());
- }
- private:
- std::unique_ptr<Stuff> ptr;
- };
- A get_A() {
- return A();
- }
- int main() {
- A a;
- A b = std::move(a);
- A c = get_A();
- A d = std::move(get_A());
- std::cout << a.id << b.id << c.id << d.id << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement