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 int *i = gettmp().get_i();
  20. cout << "end" << endl;
  21.  
  22. cout << "[Danger] i is dangling here" << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Begin
tmp destroyed
end
[Danger] i is dangling here