我想知道是否可以将实际的子例程放在类型绑定过程和不同文件中的类型定义后面。例如:
档案一:
Module TypeDef
Type :: Test
Integer :: a,b,c
contains
Procedure, Pass, Public :: add => SubAdd
End Type
Type(Test) :: Test
Interface
Subroutine SubAdd(this)
Import TypeDef
Class(TypeDef), Intent(InOut) :: this
End Subroutine
End Interface
End Module
文件 B:
Module TypeRoutines
use TypeDef
Private :: SubAdd
contains
Subroutine SubAdd(this)
Class(TypeDef), Intent(InOut) :: this
this%c=this%a+this%b
End Subroutine
End Module
这不起作用,因为当先编译文件 A 然后编译文件 B 时,ifort
会给出错误消息:
The name of the module procedure conflicts with a name in the encompassing scoping unit
主要原因是,对于某些类型,我必须编写大量类型绑定的过程,并且有些文件扩展了数百行,这使得工作非常乏味。最终目标是将每个子例程放入不同的文件中。
有任何想法吗?