Advertisement
qberik

Untitled

May 31st, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <functional>
  2.  
  3. int f1(int a, int b, bool c)
  4. {
  5. return c ? a + b : a - b;
  6. }
  7.  
  8. int f2(int a )
  9. {
  10. return a * 2;
  11. }
  12.  
  13. int f3(){
  14. return 0;
  15. }
  16.  
  17. void f4(){
  18. int a;
  19. int b;
  20. }
  21.  
  22. template <typename R, typename... Args>
  23. R call(void* funcaddr, Args... args)
  24. {
  25. typedef R(*Function)(Args...);
  26. Function fnptr = (Function)funcaddr;
  27. return fnptr(args...);
  28. }https://pastebin.com/
  29.  
  30. int main(){
  31.  
  32.  
  33. call<int>( (void*)f1, 42, 10, true);
  34. call<int>( (void*)f2, 42 );
  35. call<int>( (void*)f3 );
  36. call<void>( (void*)f4 );
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement