using NAG c functions in c++

P

pauldepstein

The following is a common problem but seems to be quite difficult.
I have the NAG library, written in C, which gives an algorithm for
finding the zeroes of a function. The problem is that the function
for which I want to find the zeroes has the form double A::f (double
x) where f is a function defined in class A and where f makes use
of the member variables in A.

I expect that this will bring up issues that I have to research on my
own but I'm short of time and would like web references rather than
book references if possible.

Thank you very much for your help.

Paul Epstein
 
A

Abhishek Padmanabh

The following is a common problem but seems to be quite difficult.
I have the NAG library, written in C, which gives an algorithm for
finding the zeroes of a function. The problem is that the function
for which I want to find the zeroes has the form double A::f (double
x) where f is a function defined in class A and where f makes use
of the member variables in A.

I expect that this will bring up issues that I have to research on my
own but I'm short of time and would like web references rather than
book references if possible.

Seems you have issues passing or using a class member function in C code.
The idea to work this out would be to introduce a wrapper extern "C"
function that internally creates an object of A with required parameters and
puts it into as needed state and then call its member function. Now, the C
code can use this wrapper function for its work (probably passing a function
pointer to the NAG lib C function call) rather than the C++ member function.
(Instead of the class object, there is another way to create a C-style
struct for the class members and member function be implemented as a extern
"C" function that operates on a instance of this struct and use that instead
but its your call to see which one suits better). Basically, try looking up
for extern C.

If the C/C++ code mix is not what you are trying to figure out then you
would need to probably explain better with some code as to what you are
trying and what problem you are facing.
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top