fork download
  1. #include <memory>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. struct Node {
  6. shared_ptr<Node> next;
  7. string value;
  8. ~Node() { cout << "destroyed object with value " << value << endl; }
  9. };
  10. int main(){
  11. shared_ptr<Node> a = make_shared<Node>();
  12. shared_ptr<Node> b = make_shared<Node>();
  13. shared_ptr<Node> c = make_shared<Node>();
  14. a->value = "a";
  15. b->value = "b";
  16. c->value = "c";
  17. a->next = b;
  18. b->next = c;
  19. c->next = a;
  20. cout << "Done!\n";
  21. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Done!