【发布时间】:2023-03-22 02:25:01
【问题描述】:
我正在尝试将过程指针传递给派生类型绑定过程
module mymodule
use mystoremodule
implicit none
private
type, abstract, public :: mytype
contains
procedure :: parse
end type mytype
contains
subroutine parse(self,mypointer)
implicit none
! Declaring Part
class(mytype) :: self
procedure(storing),pointer, intent(in) :: mypointer
integer :: myvalue
! Executing Part
myvalue = 42
call mypointer(myvalue)
end subroutine parse
end module mymodule
storing 在另一个模块/派生类型中定义
module mystoremodule
implicit none
type, public :: storingtype
integer :: myvalue
contains
procedure, public :: storing
end type storingtype
contains
subroutine storing(self,myvalue)
! Declaring part
class(storingtype) :: self
integer, intent(in) :: myvalue
! Executing part
self%myvalue = myvalue
end subroutine SetExcitationOrder
end module mystoremodule
我调用这个过程
call mytypeobject%parse(storingtypeobject%storing)
这样我得到一个编译器错误
The type of the actual argument differs from the type of the dummy argument.
我发现错误来自过程指针没有将虚拟参数传递给storing 过程(我没有将任何东西定义为nopass)。在所有其他情况下,虚拟参数会自动传递,为什么不在这里呢?声明虚拟参数对我来说是不可行的,因为过程使用的对象发生了变化。
我的问题有什么解决方案吗?
【问题讨论】:
-
你能展示一个完整的程序,或者至少展示所有相关的声明吗?
-
抱歉,因为代码是机密的,所以不可能。您是否遗漏了声明的特定部分?
-
我们可能会假设
type(mytype) mytypeobject和type(storingtype) storingtypeobject但确认会很好。 -
This question 也可能感兴趣。
标签: fortran fortran2003