fork(1) download
  1. #include <iostream>
  2.  
  3. class Broken {
  4. public:
  5. Broken(int i): read_only(read_write), read_write(i) {}
  6.  
  7. int const& read_only;
  8.  
  9. void set(int i) { read_write = i; }
  10.  
  11. private:
  12. int read_write;
  13. };
  14.  
  15. int main() {
  16. Broken original(5);
  17. Broken copy(original);
  18.  
  19. std::cout << copy.read_only << "\n";
  20.  
  21. original.set(42);
  22.  
  23. std::cout << copy.read_only << "\n";
  24. return 0;
  25. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
5
42