fork download
  1. #include<bits/stdc++.h>
  2. #define IOF ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  3. #define ll long long
  4. using namespace std;
  5.  
  6. class c{
  7. int cnt;
  8. public:
  9. c():cnt(0){cout << "default\n";}
  10. c(int x):cnt(x){cout << "param\n";}
  11. int get_cnt(){return cnt;}
  12. c operator++(){
  13. cout << "pre\n";
  14. return c(++cnt);
  15. }
  16. c operator++(int){
  17. cout << "post\n";
  18. return c(cnt++);
  19.  
  20. }
  21. void operator = (c tmp){
  22. cout << "equal\n";
  23. cnt = tmp.cnt;
  24. }
  25. ~c(){
  26. cout << "des\n";
  27. }
  28.  
  29. };
  30.  
  31. int main() {
  32. c ob;
  33. c ob1(3);
  34. ob++;
  35. ++ob;
  36. ob1++;
  37. cout << ob.get_cnt() << ' ' << ob1.get_cnt() << '\n';
  38. ob = ob1++;
  39. cout << ob.get_cnt() << ' ' << ob1.get_cnt() << '\n';
  40.  
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
default
param
post
param
des
pre
param
des
post
param
des
2 4
post
param
equal
des
4 5
des
des