Advertisement
tinyevil

Untitled

Jul 29th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <vector>
  2. #include <memory>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class Foo{
  7. public:
  8.     Foo(int k)
  9.         : k1(k)
  10.         , k2(k){
  11.     }
  12.  
  13.     Foo(const Foo& foo)
  14.         : k1(foo.k1){
  15.         std::cout << foo.foo->k1 << " " << foo.foo->k2 << "\n";
  16.         k2 = foo.k2;
  17.     }
  18.  
  19.     void set_other(const shared_ptr<Foo>& other){
  20.         foo = other;
  21.     }
  22. private:
  23.     int k1, k2;
  24.     shared_ptr<Foo> foo;
  25. };
  26.  
  27. int main(){
  28.     shared_ptr<Foo> a = make_shared<Foo>(1);
  29.     shared_ptr<Foo> b = make_shared<Foo>(2);
  30.  
  31.     b->set_other(a);
  32.  
  33.     *a = *b;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement