我正在使用几种派生类型.出于调试目的,我想通过使用一个很好的方式在屏幕上打印它们generic :: write(formatted).
这是一个显示我的意思的示例程序:
program main
use :: test_mod
implicit none
type(test1) :: t1
type(test2) :: t2
t1 = test1(name="t1")
t2 = test2(name="t2", t1)
print *, 'Test1:', t1
print *, 'Test2:', t2
end program
Run Code Online (Sandbox Code Playgroud)
这是模块:
module test_mod
implicit none
private
public :: test1, test2
type :: test1
character(2) :: name
contains
procedure, private :: test1_writef
generic :: write(formatted) => test1_writef
end type test1
type :: test2
character(2) :: name
type(test1) :: t1
contains
procedure, private :: test2_writef
generic …Run Code Online (Sandbox Code Playgroud)