考虑可访问性:只要类型可访问,公共类型绑定过程就可以访问。
module mod
private
type, public :: type1
contains
procedure, nopass :: proc
end type
contains
subroutine proc
end subroutine
end module
use mod
type(type1) t1
call t1%proc
call proc ! No, we can't call proc from mod1
end
同样,与use <module>, only <...>
module mod1
type type1
contains
procedure, nopass :: proc
end type
contains
subroutine proc
end subroutine
end module
module mod2
type type2
contains
procedure, nopass :: proc
end type
contains
subroutine proc
end subroutine
end module
我们可以避免模块过程名称中的冲突,而无需在使用关联上重命名:
use mod1, only : type1
use mod2, only : type2
type(type1) t1
type(type2) t2
call t1%proc
call t2%proc ! These aren't ambiguous
end
为了避免过程中出现歧义,我们必须重命名:
use mod1, proc1=>proc
use mod2, proc2=>proc
call proc1
call proc2
end
还有过程参考的动态选择:
module mod
type type1
contains
procedure, nopass :: proc=>proc1
end type
type, extends(type1) :: type2
contains
procedure, nopass :: proc=>proc2
end type
contains
subroutine proc1
end subroutine
subroutine proc2
end subroutine
end module
use mod
class(type1), allocatable :: t
t=type1()
call t%proc ! proc1
t=type2()
call t%proc ! proc2
end
但应该注意的是,像这样的绑定名称t1%proc
与过程名称不同
use mod
type(type1) t1
call sub(proc1) ! Where this is accessible
call sub(t1%proc) ! We cannot do this
contains
subroutine sub(proc)
procedure() proc
end subroutine
end