fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Ref
  5. {
  6. int &r;
  7. Ref(int &r):r(r) {}
  8. void change(int &r) { *((int**)this)=&r; }
  9. void show() { cout<<&r<<'\t'<<r<<endl; }
  10. };
  11.  
  12. int main()
  13. {
  14. int a=0;
  15. Ref r(a);
  16. r.show();
  17. int x=123456789; r.change(x); r.show();
  18. int y=987654321; r.change(y); r.show();
  19. return 0;
  20. }
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
0xbff0a098	0
0xbff0a090	123456789
0xbff0a08c	987654321