fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct foo {};
  5.  
  6. foo& operator<<(foo& f, int data)
  7. {
  8. cout << "int: " << data;
  9. return f;
  10. }
  11.  
  12.  
  13. foo& operator<<(foo& f, const char* data)
  14. {
  15. cout << "char: " << data;
  16. return f;
  17. }
  18.  
  19. foo& debug_out()
  20. {
  21. static foo foo_;
  22. return foo_;
  23. }
  24.  
  25. typedef enum {
  26. Ok = 0,
  27. NonOk = 10
  28. } MyEnum;
  29.  
  30. foo& operator<<(foo& out, MyEnum var)
  31. {
  32. switch(var)
  33. {
  34. case Ok:
  35. return out << "Ok";
  36. case NonOk:
  37. return out << "NonOk";
  38. default:
  39. return out << "wrong val: " << static_cast<int>(var);
  40. }
  41. };
  42.  
  43. int main() {
  44. // your code goes here
  45. debug_out() << 10;
  46. cout << endl;
  47. debug_out() << "10";
  48. cout << endl;
  49. debug_out() << NonOk;
  50. cout << endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
int: 10
char: 10
char: NonOk