fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct S { S(int val = 0) : i(val) {} int i; };
  5.  
  6. struct T
  7. {
  8. T(int Sp = 0) { c = std::shared_ptr<S>(new S(Sp)); }
  9.  
  10. std::shared_ptr<S> c;
  11.  
  12. };
  13.  
  14. int main()
  15. {
  16. T objectA(1);
  17.  
  18. // Points to the same pointer; shared resources
  19. T objectB = objectA;
  20.  
  21. // Pointers point to same resource
  22. std::cout << std::hex << objectA.c.get() << std::endl;
  23. std::cout << objectB.c.get() << std::endl;
  24. }
  25.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
0x8aa7a10
0x8aa7a10