fork(1) download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. struct Foo
  5. {
  6. ~Foo() { std::cout << "Foo\n"; }
  7. };
  8.  
  9. struct Bar : public Foo
  10. {
  11. ~Bar() { std::cout << "Bar\n"; }
  12. };
  13.  
  14. int main()
  15. {
  16. {
  17. std::cout << "shared_ptr:\n";
  18. std::shared_ptr<Foo> f(new Bar()); // prints Bar Foo
  19. }
  20.  
  21. {
  22. std::cout << "unique_ptr:\n";
  23. std::unique_ptr<Foo> f(new Bar()); // prints Foo
  24. }
  25. }
  26.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
shared_ptr:
Bar
Foo
unique_ptr:
Foo