
On Fri, Aug 28, 2009 at 4:16 AM, Daniele Barzotti<daniele.barzotti@eurocomtel.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
I would ask you a suggestion. In according with the FAQ (http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.2) is better to not set a non-static member function like a callback.
But If I need to pass that callback inside my object, I'm pretty sure that the object itself exist!
So if I have a callback signature like this:
int my_callback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, int status, void *userData )
And I want to bind it to a member function:
int MyObject::my_callback(....)
Now, inside the object I have something like:
MyObject::OneMethod() { p_AnotherObject->SetCallBack( ???? ); }
How can I pass my MyObject::my_callback to SetCallBack using boost::function and/or boost::bind?
If the callback is a real function pointer and not boost::function, you cannot. Bind creates a functor, which cannot be placed in a C style function pointer, you need a C++ style function pointer (std/boost::function). Your best bet would be to stick the instance in the userData and call back to your instance.