fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct Container {
  5. std::string s;
  6.  
  7. Container() {
  8. s = "Init";
  9. std::cout << "Constructed" << std::endl;
  10. }
  11.  
  12. ~Container() {
  13. s = "UNSAFE";
  14. std::cout << "Destructed" << std::endl;
  15. }
  16.  
  17. const std::string& GetS() const {
  18. return s;
  19. }
  20. };
  21.  
  22. int main() {
  23. const std::string& s = Container().s;
  24. std::cout << s << std::endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Constructed
Init
Destructed