我试图过程指针传递给一个派生类型结合-过程传递过程指针到派生类型结合-过程
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
)。在所有其他情况下,虚拟参数会自动传递,为什么不在这里?作为过程使用的对象发生变化,我声明伪参数是不可行的。 有没有解决我的问题的方法?
你能展示一个完整的程序,或至少显示所有相关的声明吗? – francescalus
对不起,因为代码是保密的,所以不可能。你是否错过了声明的特定部分? – THo
我们可以假设'type(mytype)mytypeobject'和'type(storedtype)storedtypeobject',但确认那会很好。 – francescalus