Boost logo

Boost Users :

Subject: [Boost-users] Define a callback member function inside the object instance
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-08-28 06:16:32


-----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?

Thanks!
Daniele.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iD8DBQFKl65//l+kMioSZwgRAkA8AKCdk44mlTXESXQJUG7vzqVnUHFoXgCghGW5
Icf+E8uX8cLwwfkdnCFmoKs=
=s1nk
-----END PGP SIGNATURE-----


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net