Re: Deal with C style function pointer callback in an object
On May 16, 8:12 am, Dat Chu <dattan...@gmail.com> wrote:
I want to write an class that hide away the function pointer
callbacks. That is:
Normally i create this function:
void errorCallback(char * err_msg)
then I call
registerErrorCallback(&errorCallback)
Then when there is an error in this third party module, my
errorCallback function will get called.
However, I would like to make this as a clean OO
implementation. I face with a problem, how can I pass a
function to registerErrorCallback that when call will make
some change the state of my object?
If you're defining it, you can either use a pointer to an
abstract base class, requiring the client to derive his callback
from this base class, or you can use something like
boost::function (which IIRC will be in the next version of the
standard).
If you're dealing with an existing C interface, you're stuck.
(But most such interfaces provide an additional void* for user
data---you can use this to pass a pointer to your abstract base
class or functional object.)
`
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34