fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Test
  8. {
  9. public:
  10. Test(string& s) : ref(s) {}
  11.  
  12. void modify() { ref = "modified"; }
  13.  
  14. string const& get() const { return ref; }
  15.  
  16. private:
  17.  
  18. string& ref;
  19. };
  20.  
  21. #define DBG(x) { cout << left << setw(30) << #x << (x) << endl; }
  22.  
  23. main()
  24. {
  25. string s = "x";
  26.  
  27. Test x(s);
  28.  
  29. DBG(x.get());
  30.  
  31. x.modify();
  32.  
  33. DBG(x.get());
  34.  
  35.  
  36. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
x.get()                       x
x.get()                       modified