http://ideone.com/OnsDWr1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
struct Extension
{
void f(){std::cout<<"f"<<std::endl;}
float g(int x, float y, int z)
{
std::cout << "x = " << x << std::endl
<< "y = " << y << std::endl
<< "z = " << z << std::endl;
return 4.5f;
}
};
template<typename R, typename... Args>
R CallExtMF(Extension &ext, void *f, Args... args)
{
R (Extension::*mfp)(Args...) = *reinterpret_cast<R (Extension::**)(Args...)>(&f);
return (ext.*mfp)(args...);
}
int main()
{
void *f = reinterpret_cast<void *>(&Extension::f);
void *g = reinterpret_cast<void *>(&Extension::g);
Extension e;
CallExtMF<void>(e, f);
float p = 2.5f;
float rv = CallExtMF<float>(e, g, 1, *reinterpret_cast<int *>(&p), 3);
std::cout << "rv = " << rv << std::endl;
}
|
I need this for retrofitting a project - don't ask. Just thought I would horrify some of you.
Last edited on
I'm gagging and vomiting at the same time. I'm.. ga-vomiting.
Last edited on
@ne555 I plead guilty, I don't need a trial.