Hi,
In order to use an external api call that requires a function pointer I
am currently creating static wrappers to call my objects functions.
I want to re-jig this so I only need 1 static wrapper function.
I would prefer to be able to pass the member function as a void* to the
static wrapper but I suspect this may not even be possible.
Another solution would be option 2 below but I can't figure out the
syntax to call obj->*pFn().
Thanks in advance for any suggestions / observations.
typedef void (*ExecFn)(void *);
void external_api_fn (ExecFn fn,void* p)
{
fn(p);
}
class Doit
{
public:
void fn1(void){print f("fn1\n");}
void fn2(void){print f("fn2\n");}
//current solution
static void static_wrapper1 (void *obj)
{
((Doit*)obj)->fn1();
}
static void static_wrapper2 (void *obj)
{
((Doit*)obj)->fn2();
}
//option 1
static void static_wrapper3 (void *fn)
{
//fn();
}
//option 2
void (Doit::*pFn)(vo id);
static void static_wrapper4 (void *obj)
{
//execute pFn - obj->*pFn - how to execute pFn for obj?
}
//--
Doit()
{
//what Im doing
external_api_fn (static_wrapper 1,this);
external_api_fn (static_wrapper 2,this);
//option 1 - cast fn1 to void?
//external_api_fn (static_wrapper 3,fn1);
//external_api_fn (static_wrapper 3,fn2);
//option 2
pFn = fn1;
external_api_fn (static_wrapper 4,this);
pFn = fn2;
external_api_fn (static_wrapper 4,this);
}
};