【发布时间】:2019-07-15 14:51:47
【问题描述】:
在设置模块时,在派生类型定义中定义变量与在该模块的子例程中定义变量有什么区别?具体来说,我需要将数据从一个模块“传递”到另一个模块。例如MathStuffModule 在子程序中添加一些数字,然后PrintStuffModule 打印这些数字(实际问题要复杂得多,但我仍在努力了解基础知识)。
例如在下面的代码中,变量“answer”和“AddThis”之间的区别在于它们各自与模块的关系,如何/是否可以在模块外部调用它们(并且说通过到 PrintStuffModule),并在实际程序中调用/定义变量?
module MathStuffModule
type MathStuffType
integer :: answer
contains
procedure :: mathstuff1
end type MathStuffType
contains
subroutine mathstuff1(m,AddThis,number)
class(MathStuffType) :: m
real :: AddThis,number,answer
m%answer = number + AddThis
end subroutine mathstuff1
end module MathStuffModule
【问题讨论】:
-
对所有 Fortran 问题使用标签 fortran。请注意,您的代码不是 Fortran 90,但至少是 Fortran 2003。
标签: oop module fortran derived-types