fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct X {
  5. int a = 1;
  6. };
  7.  
  8. struct Y {
  9. X &_x;
  10. Y(X &x) : _x(x) {}
  11. };
  12. struct Z {
  13. X &_x;
  14. Z(X x) : _x(x) {}
  15. };
  16.  
  17. int main() {
  18. X x;
  19. Y y(x);
  20. Z z(x);
  21. cout << "x: " << &x << endl;
  22. cout << "y.x: " << &y._x << endl;
  23. cout << "z.x: " << &z._x << endl;
  24.  
  25. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
x: 0xbfa195f8
y.x: 0xbfa195f8
z.x: 0xbfa195fc