G
Gert Van den Eynde
Hi all,
What is "the best" way to have a callback from a C (or a Fortran) routine to
a member function of a class? An example: I have objects of a class where
double operator(double) is defined. I have a both a C and Fortran routine -
that I cannot modify, nor convert to C or whatever, I'm stuck with them -
that take a double f(double) function pointer as argument. These C and
Fortran routines do a numerical quadrature using the object's operator().
Hence, I need to provide this C function with a pointer to a member
function. I've read the chapter in the C++ faq lite, I've come across the
function pointer tutorial and read that and tested this approach (and it
worked). But I was wondering if there is a more elegant way (no more global
variables and such). I'm not really following TR1, but I heard something of
a tr1::function, tr1::mem_fn etc. Can they be used to clean up the code?
Thanks,
gert
What is "the best" way to have a callback from a C (or a Fortran) routine to
a member function of a class? An example: I have objects of a class where
double operator(double) is defined. I have a both a C and Fortran routine -
that I cannot modify, nor convert to C or whatever, I'm stuck with them -
that take a double f(double) function pointer as argument. These C and
Fortran routines do a numerical quadrature using the object's operator().
Hence, I need to provide this C function with a pointer to a member
function. I've read the chapter in the C++ faq lite, I've come across the
function pointer tutorial and read that and tested this approach (and it
worked). But I was wondering if there is a more elegant way (no more global
variables and such). I'm not really following TR1, but I heard something of
a tr1::function, tr1::mem_fn etc. Can they be used to clean up the code?
Thanks,
gert