fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string& staticWeirdness()
  5. {
  6. static string* internal = new string("Set in staticWeirdness");
  7. return *internal;
  8. }
  9.  
  10. void screwery()
  11. {
  12. string stealer("Stole your string!");
  13. staticWeirdness() = stealer;
  14. }
  15.  
  16. int main() {
  17. string yep = staticWeirdness();
  18. string* yepPtr = &yep;
  19. cout << yep << endl;
  20. screwery();
  21. string nope = staticWeirdness();
  22. cout << &nope << endl;
  23. cout << yepPtr << endl;
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Set in staticWeirdness
0x7ffcca697e50
0x7ffcca697e30