fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo {
  5. enum OpState {
  6. None ,
  7. PlusState ,
  8. NotState ,
  9. };
  10.  
  11. public:
  12. Foo& operator+() {
  13. cout << "operator+()" << endl;
  14. opState = PlusState;
  15. return *this;
  16. }
  17. Foo& operator!() {
  18. cout << "operator!()" << endl;
  19. switch(opState) {
  20. case PlusState:
  21. operatorexclamativeplus();
  22. opState = None;
  23. break;
  24. default:
  25. opState = NotState;
  26. break;
  27. }
  28. return *this;
  29. }
  30.  
  31. private:
  32. Foo& operatorexclamativeplus() {
  33. cout << "operatorexclamativeplus()" << endl;
  34. opState = None;
  35. return *this;
  36. }
  37. Foo& operatorexclamativeplus(const Foo& rhs) {
  38. cout << "operatorexclamativeplus(const Foo& rhs)" << endl;
  39. opState = None;
  40. return *this;
  41. }
  42.  
  43. OpState opState;
  44. };
  45.  
  46.  
  47. int main() {
  48. Foo x;
  49. Foo z = !+x;
  50. return 0;
  51. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
operator+()
operator!()
operatorexclamativeplus()