fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Foo {
  6. public:
  7. void bar(int) { cout << "bar" << endl; }
  8. };
  9.  
  10. template< class T, typename ...Args, void(T::*Member)(Args...) >
  11. void member_dispatch(Args&&... args, void* userdata)
  12. {
  13. T* obj = static_cast<T*>(userdata);
  14. (obj->*Member)(std::forward<Args>(args)...);
  15. }
  16.  
  17. int main()
  18. {
  19. Foo foo;
  20. member_dispatch<Foo, int, &Foo::bar>(1, &foo);
  21. return 0;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:49: error: no matching function for call to ‘member_dispatch(int, Foo*)’
     member_dispatch<Foo, int, &Foo::bar>(1, &foo);
                                                 ^
prog.cpp:11:6: note: candidate: template<class T, class ... Args, void (T::* Member)(Args ...)> void member_dispatch(Args&& ..., void*)
 void member_dispatch(Args&&... args, void* userdata)
      ^~~~~~~~~~~~~~~
prog.cpp:11:6: note:   template argument deduction/substitution failed:
stdout
Standard output is empty