我想知道是否有一种优雅的方法来避免在 SELECT TYPE
构造中重复适用于不同类型的代码块。例如:
select type (var)
type is (t1_t)
codeA (many lines of code)
type is (t2_t)
codeA (same lines)
...
type is (tn_t)
codeB
class default
codeC
end select
我想知道是否有一种优雅的方法来避免在 SELECT TYPE
构造中重复适用于不同类型的代码块。例如:
select type (var)
type is (t1_t)
codeA (many lines of code)
type is (t2_t)
codeA (same lines)
...
type is (tn_t)
codeB
class default
codeC
end select
select type (var)
type is (t1_t)
! Here, type of var is t1_t, and you can call
! procedures that use type(t1_t) as arguments with var
type is (t2_t)
! Here, type of var is t2_t, and procedures expecting
! type(t1_t) as arguments won't work with var
...
end select
var
传递给该例程,则必须将其声明为多态虚拟参数。included.f90:
codeA (many lines of code)
main.f90:
select type (var)
type is (t1_t)
include "included.f90"
type is (t2_t)
include "included.f90"
...
end select
#include
。有一种重载运算符类型的构造,它建议使用“类型为”。这需要作为子例程或函数在模块中。我大多数情况下使用函数,所以如果与C混合使用,则子例程可能比尝试返回向量的函数更容易。
它仍将是完全相同的代码,只是操作复杂、浮点、双精度或各种整数但深度不同...因此没有明确的“类型”,因为右侧版本是基于参数类型选择的。
include
。 - francescalus