Hi
I am trying to pass a callback which is a member function. I understand that a function pointer and a member function pointer are different and have tried to create a wrapper and use a static cast and the void pointer. Unfortunately I am missing something as my code produces an error at compile
Error 16 error C2664: 'dSpaceCollide' : cannot convert parameter 3 from 'int (__cdecl *)(void *,void *,dGeomID,dGeomID)' to 'dNearCallback (__cdecl *)'
My code…..
class ODEPhysics
header file
void NearCallback (void* data, dGeomID o1, dGeomID o2);
static int StaticNearCallback(void* data, void* userPtr, dGeomID o1, dGeomID o2);
.cpp file
void ODEPhysics::NearCallback (void* data, dGeomID o1, dGeomID o2){.........}
void ODEPhysics::StaticNearCallback(void* data , void* userPtr, dGeomID o1, dGeomID o2)
{
static_cast<ODEPhysics*>(userPtr)->NearCallback( data, o1, o2);
}
dSpaceCollide (Space, 0, &ODEPhysics::StaticNearCallback);
If anyone could clarify what I am doing wrong and why it would be greatly appreciated.
Fred
The problem is most likely, from what you show, that
dSpaceCollidejust wants acallback, that is, a function with a single
void*user-data pointer and the twodGeomIDs as parameters. Thevoid*is whatever data you passed to thedSpaceCollidethen.Assuming
dSpaceCollideis defined something like this:You can then change the callbacks to this:
No more need for the
void* datapointer in the member function, as thatdatais only relevant for the static callback: