fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. protected:
  6. int &_y = _x[0];
  7. int _x[2];
  8. public:
  9. void setX(int x) {
  10. _x[0] = x;
  11. }
  12. int getX() {
  13. return _x[0];
  14. }
  15. void setY(int y) {
  16. _y = y;
  17. }
  18. int getY() {
  19. return _y;
  20. }
  21. };
  22.  
  23. int main() {
  24. A a;
  25. a.setY(0);
  26. a.setX(5);
  27. cout << "x = " << a.getX() << endl;
  28. cout << "y = " << a.getY() << endl;
  29. cout << endl;
  30.  
  31. a.setY(7);
  32. cout << "x = " << a.getX() << endl;
  33. cout << "y = " << a.getY() << endl;
  34.  
  35. // your code goes here
  36. return 0;
  37. }
Success #stdin #stdout 0s 4364KB
stdin
Standard input is empty
stdout
x = 5
y = 5

x = 7
y = 7