Possible Duplicate:
How can I pass a class member function as a callback?
I have two classes A and B
class A
{
public:
void SetHandler(void (*p)(OMX_BUFFERHEADERTYPE*)){ Handler = p; };
private:
void (*Handler)(OMX_BUFFERHEADERTYPE*);
}
and
in B I have a function
void B::handler(OMX_BUFFERHEADERTYPE* p){};
now when (from B) I call
inst_a.SetHandler(&B::handler);
i get the following error:
B.cpp:740:69: error: no matching function for call to ‘A::SetHandler(void (COMXVideo::*)(OMX_BUFFERHEADERTYPE*))’
B.cpp:740:69: note: candidate is:
A.h:161:8: note: void A::SetHandler(void (*)(OMX_BUFFERHEADERTYPE*))
A.h:161:8: note: no known conversion for argument 1 from ‘void (B::*)(OMX_BUFFERHEADERTYPE*)’ to ‘void (*)(OMX_BUFFERHEADERTYPE*)’
what am I doing wrong?
Best Regards
&B::handleris not a function pointer, but a pointer to member function. IfB::handlerdoesn’t need members ofB, you can define itstatic. ThenSetHandler(&B::handler)will work.If you must have a pointer to member function, you can define it as
when you call such a member function, you need a pointer to an object as well
or with a reference