fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define GEN_MESSAGE_INVOKER(FuncName) \
  5.   class\
  6.   { \
  7.   public: \
  8.   template <class C> \
  9.   static void Invoke (C &item, decltype (C::FuncName)) \
  10.   { \
  11.   item.FuncName (); \
  12.   } \
  13.   \
  14.   template <class C> \
  15.   static void Invoke (C &item, ...) \
  16.   {} \
  17.   }
  18.  
  19.  
  20. class A
  21. {
  22. void OnDerp ()
  23. {
  24. cout << "Derpin!" << endl;
  25. }
  26. };
  27.  
  28. class B
  29. {
  30. };
  31.  
  32. template <class I>
  33. void InvokeMessage ()
  34. {
  35. A a;
  36. B b;
  37. I::Invoke (a,0); //0 goes to either ... or the decltype pointer param.
  38. I::Invoke (b,0);
  39. }
  40.  
  41. int main()
  42. {
  43. InvokeMessage <GEN_MESSAGE_INVOKER(OnDerp)>();
  44. return 0;
  45. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:43:17: error: invalid declaration of member template in local class
prog.cpp:43:17: error: invalid declaration of member template in local class
prog.cpp:43:45: error: expected class-name before '(' token
prog.cpp:43:45: error: expected '::' before '(' token
prog.cpp:43:45: error: expected identifier before '(' token
prog.cpp:43:46: error: expected unqualified-id before ')' token
stdout
Standard output is empty