小编Sub*_*iva的帖子

将类型绑定过程作为参数传递

我试图将类型绑定过程作为参数传递给另一个子例程.我想知道Fortran中是否可行.这是一个代码片段,显示了我想要做的事情.

module type_definitions 
 type test_type 
 integer :: i1, i2,i3
 contains 
   procedure :: add_integers_up 
 end type test_type
 contains 
   subroutine add_integers_up(this,i4,ans)
       class(test_type) :: this 
       integer :: i4,ans 
       ans = this%i1+this%i2+this%i3+i4
    end subroutine add_integers_up

subroutine print_result_of_subroutine(i4,random_subroutine) 
  integer :: i4,ans 

  interface 
     subroutine  random_subroutine(i1,i2) 
       integer:: i1,i2
     end subroutine random_subroutine
  end interface

  call random_subroutine(i4,ans) 
  write(*,*) ans 


end subroutine print_result_of_subroutine


end module type_definitions


program main 
   use type_definitions
   implicit none 
   integer :: i1,i2,i3,i4
   integer :: ans 
   type(test_type) :: test_obj

   i1 =1; i2=2; i3=3
   test_obj%i1 = i1 
   test_obj%i2 = …
Run Code Online (Sandbox Code Playgroud)

fortran function user-defined-types fortran2003

4
推荐指数
1
解决办法
1507
查看次数