我已经用Java编程了几年; 但是,我现在正在学习一门使用Fortran作为示例代码(77标准)的课程.虽然我一直认为Fortran是一种古老的语言,但我决定使用gfortran编译器试用2003标准的最新实现来看看它的优点.到目前为止,我对现代功能感到惊讶,但我遇到了一个问题,下面的例子证明了这个问题.
module mod1
type type1
real :: x
real :: y
contains
procedure :: compute
end type type1
contains
subroutine compute(this)
class(type1) :: this
this%y = this%x*2 - 1
write (*,*) this%x,this%y
end subroutine
end module mod1
module mod2
type type2
real :: x
real :: y
contains
procedure :: compute
end type type2
contains
subroutine compute(this)
class(type2) :: this
this%y = this%x - 5
write (*,*) this%x,this%y
end subroutine
end module mod2
program test
use mod1
use mod2 …Run Code Online (Sandbox Code Playgroud)