fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <tuple>
  4. #include <vector>
  5.  
  6. #define USE_MEDIATOR
  7.  
  8. using namespace std;
  9.  
  10. template<class T>
  11. void show(T tup)
  12. {
  13. cout << "-----------------" << endl;
  14. cout << get<0>(tup) << endl;
  15. cout << get<1>(tup) << endl;
  16. cout << get<2>(tup) << endl;
  17. cout << "-----------------" << endl;
  18. }
  19.  
  20. template <class T>
  21. class NotifyParam
  22. {
  23. public:
  24. NotifyParam(T body)
  25. :body(body)
  26. {}
  27. T body;
  28. };
  29.  
  30. #ifdef USE_MEDIATOR
  31.  
  32. class MediatorBase
  33. {
  34. public:
  35. virtual void doCommand(NotifyParam notifyParam) = 0;
  36. };
  37.  
  38. class MediatorA : public MediatorBase
  39. {
  40. public:
  41. virtual void doCommand(NotifyParam notifyParam)
  42. {
  43. cout << "-----------------" << endl;
  44. cout << "----MediatorA----" << endl;
  45. show(notifyParam.body);
  46. }
  47. };
  48.  
  49. class MediatorB : public MediatorBase
  50. {
  51. public:
  52. virtual void doCommand(NotifyParam notifyParam)
  53. {
  54. cout << "-----------------" << endl;
  55. cout << "----MediatorB----" << endl;
  56. show(notifyParam.body);
  57. }
  58. };
  59.  
  60. #endif
  61.  
  62. int main ()
  63. {
  64. auto tup1 = make_tuple("A", 1, 0.3);
  65. NotifyParam<decltype(tup1)> pp1(tup1);
  66. show(pp1.body);
  67.  
  68. auto tup2 = make_tuple("B", "cc", 1);
  69. NotifyParam<decltype(tup2)> pp2(tup2);
  70. show(pp2.body);
  71.  
  72. #ifdef USE_MEDIATOR
  73.  
  74. vector<MediatorBase*> vt = {new MediatorA, new MediatorB};
  75.  
  76. for(auto it : vt)
  77. {
  78. it->doCommand(pp1.body);
  79. it->doCommand(pp2.body);
  80. }
  81.  
  82. #endif
  83.  
  84. return 0;
  85. }
  86.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:35:28: error: 'NotifyParam' is not a type
     virtual void doCommand(NotifyParam notifyParam) = 0;
                            ^
prog.cpp:41:28: error: 'NotifyParam' is not a type
     virtual void doCommand(NotifyParam notifyParam)
                            ^
prog.cpp: In member function 'virtual void MediatorA::doCommand(int)':
prog.cpp:45:26: error: request for member 'body' in 'notifyParam', which is of non-class type 'int'
         show(notifyParam.body);
                          ^
prog.cpp: At global scope:
prog.cpp:52:28: error: 'NotifyParam' is not a type
     virtual void doCommand(NotifyParam notifyParam)
                            ^
prog.cpp: In member function 'virtual void MediatorB::doCommand(int)':
prog.cpp:56:26: error: request for member 'body' in 'notifyParam', which is of non-class type 'int'
         show(notifyParam.body);
                          ^
prog.cpp: In function 'int main()':
prog.cpp:78:31: error: no matching function for call to 'MediatorBase::doCommand(std::tuple<const char*, int, double>&)'
         it->doCommand(pp1.body);
                               ^
prog.cpp:35:18: note: candidate: virtual void MediatorBase::doCommand(int)
     virtual void doCommand(NotifyParam notifyParam) = 0;
                  ^
prog.cpp:35:18: note:   no known conversion for argument 1 from 'std::tuple<const char*, int, double>' to 'int'
prog.cpp:79:31: error: no matching function for call to 'MediatorBase::doCommand(std::tuple<const char*, const char*, int>&)'
         it->doCommand(pp2.body);
                               ^
prog.cpp:35:18: note: candidate: virtual void MediatorBase::doCommand(int)
     virtual void doCommand(NotifyParam notifyParam) = 0;
                  ^
prog.cpp:35:18: note:   no known conversion for argument 1 from 'std::tuple<const char*, const char*, int>' to 'int'
stdout
Standard output is empty