场景(见下面的代码):考虑一些 Fortran 模块my_module,它包含两个派生类型的定义:test(parent) 和sub_test(extends test, subclass)。除了两个构件a和b父类的,sub_test定义了一个新成员c。最终,该模块my_module将用于某些程序中my_program。
module my_module
implicit none
private
public :: test, sub_test
type :: test
integer :: a = 1
integer :: b = 2
end type test
type, extends(test) :: sub_test
integer :: c = 3
contains
procedure, public :: increment
end type sub_test
contains
subroutine increment (this)
class(sub_test) :: this
this % a = this …Run Code Online (Sandbox Code Playgroud)