pointing to a member function/method within another function

U

uli

Hi all,
I've learned native C and I'm trying to write now in C++. I want to use a
simple routine from the "Numerical Recipes in C" for using a Newton-Raphson
Method within my c++ class. The Newton-Raphson function for finding roots is
called:
float rtsafe(void (*funcd)(float, float *, float *), float x1, float x2,
float xacc)

'funcd' is the pointer to an external function as common in C. But since I
want to use it with a member function of my class for computing its roots, I
think I can't do that, because member functions are adressed relative to my
class.

Could anyone please give me some hints what I have to do, so that I can use
an external function like this and give it member functions for computation.
(Please apologise my bad style talking about coding...)

Thanx a lot,
uli
 
J

John Harrison

uli said:
Hi all,
I've learned native C and I'm trying to write now in C++. I want to use a
simple routine from the "Numerical Recipes in C" for using a Newton-Raphson
Method within my c++ class. The Newton-Raphson function for finding roots is
called:
float rtsafe(void (*funcd)(float, float *, float *), float x1, float x2,
float xacc)

'funcd' is the pointer to an external function as common in C. But since I
want to use it with a member function of my class for computing its roots, I
think I can't do that, because member functions are adressed relative to my
class.

Could anyone please give me some hints what I have to do, so that I can use
an external function like this and give it member functions for computation.
(Please apologise my bad style talking about coding...)

Hopefully this gives the idea.

float rtsafe(MyClass* my_class, void (MyClass::*funcd)(float, float *,
float *), float x1, float x2, float xacc)
{
(my_class->*funcd)(a, b, c);
}

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top