我想我可以很容易在这里使用一些帮助,因为我搞乱了一些Fortran 2003,但似乎无法理解如何做到真正的事情。 事实上,我需要编写一个Fortran代码,在模块内声明一个新的数据类型 ,该类型的成员之一是一个指向真实函数的指针。像指向Fortran模块中派生类型的函数
module new_mod
type my_type
real*8 :: a, b
(here something that declares a real*8 function), pointer :: ptr
end type my_type
end module_new
module funcs
real*8 function function1(x)
real*8 :: x
function1 = x*x
end function function1
real*8 function function2(x)
real*8 :: x
function2 = x*x
end function function2
end module funcs
的东西,然后在主程序中,我想有这样的事情
program my_prog
use module_new
use module_funcs
implicit none
real*8 :: y, z
type(my_type) :: atom
...
atom%ptr => function1
y = atom%ptr(x)
...
atom%ptr => function2
z = atom%ptr(x)
end program my_prog
而
所以主要的想法是,module_new包含有指向一个真正的类型 功能。这个新类型I的对象中的指针必须能够指向主程序中的不同功能。 我已经看到一个人可以用抽象界面等做类似的事情,但老实说,我在这里一团糟。如果有人能帮忙,我会很感激。 干杯......
谢谢!这似乎是伎俩...... – user2378824 2013-05-14 08:18:09
那么你应该接受答案。 – 2013-05-14 11:48:22