fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Foo
  4. {
  5. public:
  6. int a,b,c;
  7. double d,e,f;
  8. string text;
  9. Foo ()
  10. {
  11. cout << "Sup" << endl;
  12. }
  13. ~Foo()
  14. {
  15. cout << "R.I.P." << endl;
  16. }
  17.  
  18. static Foo& getInstanceRef()
  19. {
  20. Foo o;
  21. o.a = 42;
  22. o.text = "42";
  23. return o;
  24. }
  25. };
  26.  
  27. int main() {
  28. cout << "Creating \"a\"" << endl;
  29. Foo a;
  30.  
  31. cout << "Assigning a new value to \"a\"" << endl;
  32. a = Foo::getInstanceRef();
  33. cout << a.a << " " << a.text << endl;
  34.  
  35. cout << "Cleaning up and finishing work" << endl;
  36. return 0;
  37. }
Runtime error #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Creating "a"
Sup
Assigning a new value to "a"
Sup
R.I.P.