kind的参数必须要编译时确定,不能假定 
len的参数可以假定。 
所以,多个kind,就要写多个函数。 
 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode module m_a
  implicit none
  type :: bar(p, q)
    integer, kind :: p=4
    integer, len  :: q=10
    real(kind=p),dimension(q) :: x
  contains
    procedure:: barsub => barsub4 , barsub8
  end type bar
contains
  subroutine barsub4(this)
    type(bar(p=4,q=*)), intent(in) :: this
    write (*,*) this%q , this%p
  end subroutine barsub4
  
  subroutine barsub8(this)
    type(bar(p=8,q=*)), intent(in) :: this
    write (*,*) this%q , this%p
  end subroutine barsub8
  
end module
Program Main
  use m_a
  type(bar(4,30)) :: x4_30
  type(bar(4,20)) :: x4_20
  type(bar(8,30)) :: x8_30
  type(bar(8,20)) :: x8_20
  call x4_30%barsub()
  call x4_20%barsub()
  call x8_30%barsub()
  call x8_20%barsub()
End Program Main   |