fortran - Passing procedure pointer to derived-type-bound-procedure -


i trying pass procedure pointer derived-type-bound-procedure

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 

where storing defined in module/ derived type

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 

i call procedure by

call mytypeobject%parse(storingtypeobject%storing) 

with compiler error

the type of actual argument differs type of dummy argument. 

i found out error comes procedure pointer not passing dummy argument storing procedure (i didn't define nopass). in other cases dummy argument gets passed automatically, why not here? it's not feasible me declare dummy argument, object procedure uses changes. there solutions problem?

well not passing there procedure pointer. storingtypeobject%storing not procedure pointer, binding type-bound procedure, not pointer of kind.

i wouldn't accept pointer, procedure argument in parse.

something like:

subroutine parse(self,mypointer)     implicit none      ! declaring part     class(mytype) :: self     procedure(storing), intent(in) :: myproc     integer :: myvalue      ! executing part     myvalue = 42     call myproc(myvalue)  end subroutine parse 

and

    call mytypeobject%parse(storing_wrapper)    contains      subroutine storring_wrapper(myvalue)       integer, intent(in) :: myvalue       call storingtypeobject%storing(myvalue)     end subroutine 

i think procedure pointers useful if can changed somewhere. not in parse if need set other target in situations.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -