Fortran 打字程序
示例
为了获得类的行为,必须在模块中放置类型和相关过程(子例程和函数):
例:
module MShape
implicit none
private
type, public :: Shape
private
integer :: radius
contains
procedure :: set => shape_set_radius
procedure :: print => shape_print
end type Shape
contains
subroutine shape_set_radius(this, value)
class(Shape), intent(in out) :: self
integer, intent(in) :: value
self%radius = value
end subroutine shape_set_radius
subroutine shape_print(this)
class(Shape), intent(in) :: self
print *, 'Shape: r = ', self%radius
end subroutine shape_print
end module MShape稍后,在代码中,我们可以如下使用Shape类:
! declare a variable of type Shape type(Shape) :: shape ! call the type-bound subroutine call shape%set(10) call shape%print
热门推荐
10 老师高考后祝福语 简短
11 老婆侄女礼物祝福语简短
12 化学老师元旦祝福语简短
13 新年元旦祝福语大全简短
14 枣庄人事考试祝福语简短
15 祝福语医生文案简短英文
16 搞笑祝福语生日老师简短
17 五一祝福语大全简短最新
18 群众过春节祝福语简短