fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. struct Foo
  5. {
  6. Foo() { std::cout << "Constructing Foo" << std::endl; }
  7. ~Foo() { std::cout << "Destructing Foo" << std::endl; }
  8.  
  9. void hello() { std::cout << "Hello" << std::endl; }
  10. };
  11.  
  12.  
  13. int main()
  14. {
  15. Foo* fooPtr = new Foo();
  16.  
  17. Foo& fooRef = *fooPtr;
  18.  
  19. delete fooPtr;
  20.  
  21. fooRef.hello();
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Constructing Foo
Destructing Foo
Hello