SHARE
TWEET

Untitled

a guest Jun 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Foo {};
  2.  
  3.  
  4. class OwnsAFoo
  5. {
  6. private:
  7.  
  8.    std::shared_ptr<Foo> owned;
  9.    
  10. public:
  11.    OwnsAFoo(std::shared_ptr<Foo> foo): owned(foo)
  12.    {}
  13. }
  14.  
  15.  
  16. int main()
  17. {
  18.    std::shared_ptr<Foo> a = new Foo;
  19.    
  20.    OwnsAFoo *owner = new OwnsAFoo(a);
  21.    
  22.    a = nullptr;
  23.    
  24.    delete owner; // Foo is destroyed inside of OwnsAFoo
  25. }
RAW Paste Data
Top