fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4.  
  5. struct A : std::enable_shared_from_this<A>
  6. {
  7. ~A(){std::cout<<"abc"<<std::endl;}
  8. };
  9.  
  10. int main()
  11. {
  12. A* a = new A;
  13. std::shared_ptr<A> p1(a);
  14. std::shared_ptr<A> p2(a);
  15.  
  16. // both p1 and p2 will delete the object a
  17. }
Runtime error #stdin #stdout #stderr 0s 3476KB
stdin
Standard input is empty
stdout
abc
abc
stderr
*** Error in `./prog': double free or corruption (fasttop): 0x08521a10 ***