fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Test
  5. {
  6. private:
  7. int x;
  8. int y;
  9. public:
  10. Test (int x = 0, int y = 0) { this->x = x; this->y = y; }
  11. Test setX(int a) { x = a; return *this; }
  12. Test setY(int b) { y = b; return *this; }
  13. void print() { cout << "x = " << x << " y = " << y << endl; }
  14. };
  15.  
  16. int main()
  17. {
  18. Test obj1;
  19. obj1.setX(10).setY(20);
  20. obj1.print();
  21. return 0;
  22. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
x = 10 y = 0