fork(2) 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. friend Foo& operator+(Foo& lhs, const Foo& rhs) {
  13. cout << "operator+(Foo& lhs, const Foo& rhs)" << endl;
  14. if(lhs.opState == NotState) {
  15. return lhs.operatorexclamativeplus(rhs);
  16. }
  17. return lhs;
  18. }
  19.  
  20. Foo& operator+() {
  21. cout << "operator+()" << endl;
  22. opState = PlusState;
  23. return *this;
  24. }
  25. Foo& operator!() {
  26. cout << "operator!()" << endl;
  27. switch(opState) {
  28. case PlusState:
  29. operatorexclamativeplus();
  30. opState = None;
  31. break;
  32. default:
  33. opState = NotState;
  34. break;
  35. }
  36. return *this;
  37. }
  38.  
  39. private:
  40. void operatorexclamativeplus() {
  41. cout << "operatorexclamativeplus()" << endl;
  42. }
  43. Foo& operatorexclamativeplus(const Foo& rhs) {
  44. cout << "operatorexclamativeplus(const Foo& rhs)" << endl;
  45. return *this;
  46. }
  47.  
  48. OpState opState;
  49. };
  50.  
  51.  
  52. int main() {
  53. Foo x;
  54. Foo y;
  55. !+x;
  56. Foo z = y !+ x;
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:56:12: error: expected ‘,’ or ‘;’ before ‘!’ token
  Foo z = y !+ x;
            ^
stdout
Standard output is empty