fork download
  1. #include <iostream>
  2.  
  3. struct Extension
  4. {
  5. void f(){std::cout<<"f"<<std::endl;}
  6. float g(int x, float y, int z)
  7. {
  8. std::cout << "x = " << x << std::endl
  9. << "y = " << y << std::endl
  10. << "z = " << z << std::endl;
  11. return 4.5f;
  12. }
  13. };
  14.  
  15. template<typename R, typename... Args>
  16. R CallExtMF(Extension &ext, void *f, Args... args)
  17. {
  18. R (Extension::*mfp)(Args...) = *reinterpret_cast<R (Extension::**)(Args...)>(&f);
  19. return (ext.*mfp)(args...);
  20. }
  21.  
  22. int main()
  23. {
  24. void *f = reinterpret_cast<void *>(&Extension::f);
  25. void *g = reinterpret_cast<void *>(&Extension::g);
  26.  
  27. Extension e;
  28.  
  29. CallExtMF<void>(e, f);
  30. float p = 2.5f;
  31. float rv = CallExtMF<float>(e, g, 1, *reinterpret_cast<int *>(&p), 3);
  32. std::cout << "rv = " << rv << std::endl;
  33. }
  34.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
f
x = 1
y = 2.5
z = 3
rv = 4.5