- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I wish to call a Fortran subroutine from c++. However, one of the arguments in the subroutine is an abstract class. Attached is a simple example of an abstract class, a derived class and the calling subroutine. Is it possible to call such a subroutine from c++? How would I declare and pass the derived class?
module Fabstract implicit none type, abstract :: arithmetic contains procedure(a_action), deferred :: action end type arithmetic abstract interface subroutine a_action(this, number, result) import :: arithmetic class(arithmetic) :: this real(8), intent(in) :: number real(8), intent(out) :: result end subroutine a_action end interface type, extends(arithmetic) :: multiply real(8) :: number_value contains procedure :: action => multi_action end type multiply contains subroutine multi_action(this, number, result) class(multiply) :: this real(8), intent(in) :: number real(8), intent(out) :: result result = this%number_value * number end subroutine multi_action end module Fabstract
module Fabstract_use use Fabstract implicit none public :: math_op contains subroutine math_op(op, number) class(arithmetic), intent(in) :: op real(8), intent(in) :: number real(8) :: caluclated_value call op%action(number, caluclated_value) write(*, *) caluclated_value end subroutine math_op end module Fabstract_use
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The answer is simple - no, you cannot do this. There is no C (nor C++) interoperability for Fortran polymorphic entities
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page