fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class V
  5. {
  6. public:
  7. int vec[2];
  8. V(int a0, int a1)
  9. {
  10. vec[0]=a0;vec[1]=a1;
  11. }
  12. V operator++(int dummy)
  13. {
  14. V v(vec[0],vec[1]);
  15. for(int i=0; i<2; i++)
  16. {
  17. ++vec[i];
  18. }
  19. return v; // Now this is *not* a copy of the incremented value,
  20. // but a copy of the *previous* value!
  21. }
  22. V operator=(V other)
  23. {
  24. vec[0]=other.vec[0];
  25. vec[1]=other.vec[1];
  26. return *this;
  27. }
  28. void print()
  29. {
  30. cout << "(" << vec[0] << ", " << vec[1] << ")" << endl;
  31. }
  32. };
  33.  
  34. int main(void)
  35. {
  36. V v1(0,0), v2(1,1);
  37.  
  38. v1.print();
  39.  
  40. v1=v2++;
  41.  
  42. v1.print();
  43. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
(0, 0)
(1, 1)