fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Contador{
  5. unsigned int contador;
  6. public:
  7. Contador(int c = 0) { contador = c; };
  8. int getContador() { return contador; };
  9. Contador& operator++() {
  10. ++contador;
  11. return *this;
  12. };
  13. Contador operator++(int) {
  14. Contador temp(*this);
  15. ++*this;
  16. return temp;
  17. };
  18. };
  19.  
  20. int main() {
  21. Contador c1, c2, c3;
  22. ++c1;
  23. ++c2;
  24. ++c2;
  25. ++c2;
  26. c3 = ++c2;
  27. ++(++(++c1));
  28. c1++;
  29. c2++;
  30. c3++;
  31. cout << "c1: " << c1.getContador() << endl;
  32. cout << "c2: " << c2.getContador() << endl;
  33. cout << "c3: " << c3.getContador() << endl;
  34. }
  35.  
  36. //https://pt.stackoverflow.com/q/174895/101
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
c1: 5
c2: 5
c3: 5