fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct List
  6. {
  7. List *next = 0;
  8. };
  9.  
  10. List & operator ++ (List &x, int)
  11. {
  12. x = *x.next;
  13. return x;
  14. }
  15.  
  16. int main()
  17. {
  18. List *lst = new List();
  19. lst->next = new List();
  20.  
  21. cout << lst << ' ' << lst->next << endl;
  22.  
  23. (*lst)++;
  24. cout << lst << ' ' << lst->next << endl;
  25.  
  26. // Это упадёт
  27. //(*lst)++;
  28. //cout << lst << endl;
  29.  
  30. List lst2;
  31. lst2.next = new List();
  32.  
  33. cout << &lst2 << ' ' << lst2.next << endl;
  34.  
  35. lst2++;
  36. cout << &lst2 << ' ' << lst2.next << endl;
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
0x555ab83aae70 0x555ab83aae90
0x555ab83aae70 0
0x7ffe1772b5e0 0x555ab83abec0
0x7ffe1772b5e0 0