Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Fortran派生类型中存储对过程的引用_Fortran - Fatal编程技术网

如何在Fortran派生类型中存储对过程的引用

如何在Fortran派生类型中存储对过程的引用,fortran,Fortran,我可以在Fortran类型中存储对过程的引用吗 我的目标是通过将重复参数分组为一个类型,将其减少到Fortran子例程中。但是Fortran不允许我对外部过程执行此操作 下面是我尝试做的一个简化示例: module my_functions type mytype external :: f end type contains subroutine fa() WRITE(*,*) "yiha" end subroutine

我可以在Fortran类型中存储对过程的引用吗

我的目标是通过将重复参数分组为一个类型,将其减少到Fortran子例程中。但是Fortran不允许我对外部过程执行此操作

下面是我尝试做的一个简化示例:

module my_functions
    type mytype
        external :: f
    end type
contains
    subroutine fa()
        WRITE(*,*) "yiha"
    end subroutine

    subroutine fb(t)
        type(mytype) t
        call t%f()
    end subroutine
end module

program test
    use my_functions
    type(mytype) :: m
    m%f = fa
    call fb(m)
end program
不管格弗特兰给了我什么

     external :: f
                 1
Error: Unexpected attribute declaration statement at (1)

派生类型可以将过程指针作为组件:

implicit none

type mytype
  procedure(), pointer, nopass :: f
end type

type(mytype) m

external fa
m%f => fa

call m%f()

end

此类型有一个带有隐式接口的过程,该接口稍后作为子例程引用。因为它有一个隐式接口,指针需要
nopass
属性。

具体来说,我有一个依赖于多个用户提供的外部函数的对象,我不想每次调用该对象上的方法时都传递所有函数。