Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29001 Discussions

Calling a c++ class's member function from Fortran?

frinxor
Beginner
623 Views
I have something like this:
Class A
{
public:
void CalculateSolution();
void UpdateSolution(int newSolution);
private:
int solution;
}
where CalculateSolution calls a very time-intensive Fortran function. Is there a way the Fortran function can callback to UpdateSolution(int) every once in a while, while it is running? I've read through the mixed language topics, but that only addresses global functions.
If not, I guess I can just create a global function with a pointer to my instance of Class A to do the update?
0 Kudos
3 Replies
Steven_L_Intel1
Employee
623 Views
Fortran can't call C member functions directly - even if you can get the external name, you don't know how to pass the context it wants. Create a regular C++ wrapper function.
0 Kudos
frinxor
Beginner
623 Views
Did you mean to switch the C/C++ ?
0 Kudos
Steven_L_Intel1
Employee
623 Views
I mean write an "extern" C++ function, callable from Fortran, that calls the member function.
0 Kudos
Reply