Hi all,
I'm using a library that takes a callback function of type (void (int)) for notifying the library user about an event. Is there a good way to use the member function of a class as this callback?
If I declare a member function (void (int)) it isn't the same type as a C-style function declared in the same way, and I can't cast it. I suspect this is because the member function needs to be altered to take the appropriate object as one of it's parameters.
Thinking along these lines, I should be able to cast a static member function to the appropriate type, but unfortunately this doesn't seem to be working either. The cast of staticvoid m_fMemberCallback(int iParam);
to (void (int)) m_fMemberCallback
results in an "invalid cast to function type 'void()(int)'" error from the compiler.
I know I can get around this by just declaring a C-style function, then calling my static member function, but I'm curious if there is a better way to do this.
Hi Duoas,
Thanks for the tip, that looks like a great tutorial. Secion "3.4 How to Implement a Callback to a static C++ Member Function ?" plus the syntax examples helped me solve the problem.