小编Ema*_*ssi的帖子

`generic :: write(formatted)`groutran中的子程序被其他派生类型调用

我正在使用几种派生类型.出于调试目的,我想通过使用一个很好的方式在屏幕上打印它们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)

generics fortran gfortran

5
推荐指数
1
解决办法
145
查看次数

标签 统计

fortran ×1

generics ×1

gfortran ×1