fork download
  1. #include <utility>
  2. #include <iostream>
  3. #include <memory>
  4.  
  5. struct other
  6. {
  7. other(std::string const& foo) : m_foo(foo) {}
  8. ~other() { std::cout << "~other(" << m_foo << ")\n"; }
  9. std::string m_foo;
  10. };
  11.  
  12. int main()
  13. {
  14. std::shared_ptr<int> spi;
  15.  
  16. {
  17. std::shared_ptr<std::pair<int, other> > spp = std::make_shared<std::pair<int, other> >(42, other("arg"));
  18. spp->second.m_foo = "shared_ptr copy";
  19. spi = std::shared_ptr<int>(spp, &(spp->first));
  20. }
  21.  
  22. std::cout << *spi << "\n";
  23. std::cout << "resetting spi...\n";
  24. spi.reset();
  25. std::cout << "done.\n";
  26. }
  27.  
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
~other(arg)
42
resetting spi...
~other(shared_ptr copy)
done.