fork download
  1. #include <iostream>
  2.  
  3. struct MyInt {
  4. MyInt() : value(0) {}
  5.  
  6. MyInt& operator++() {
  7. std::cout << "Inside MyInt::operator++()" << std::endl;
  8. ++value;
  9. return *this;
  10. }
  11.  
  12. MyInt operator++(int)
  13. {
  14. MyInt temp(*this);
  15. ++(*this);
  16. return temp;
  17. }
  18.  
  19. int value;
  20. };
  21.  
  22. int main() {
  23. MyInt mi;
  24.  
  25. std::cout << "Value before: " << mi.value << std::endl;
  26. mi++++;
  27. std::cout << "Value after: " << mi.value << std::endl;
  28. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Value before: 0
Inside MyInt::operator++()
Inside MyInt::operator++()
Value after: 1