fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct tmp {
  5. int i;
  6. const int *get_i() const { return &i; }
  7. tmp() : i(42) {}
  8. ~tmp() { cout << "tmp destroyed" << endl; }
  9. };
  10.  
  11. tmp gettmp()
  12. {
  13. tmp t;
  14. return t;
  15. }
  16.  
  17. int main() {
  18. cout << "Begin" << endl;
  19. const tmp &t = gettmp();
  20. const int *i = t.get_i();
  21. cout << "end" << endl;
  22.  
  23. cout << "[Happy] i is still alive : " << *i << endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Begin
end
[Happy] i is still alive : 42
tmp destroyed