【发布时间】:2015-07-16 13:40:52
【问题描述】:
我在一个模块中有两个派生类型,Interval 和 Inrset。两者具有相同的功能,但是一个对实数进行操作,另一个对整数进行操作。
遇到的问题如下
lib/interval.f:85:11:
Procedure :: eptset => inrval_set
1
Error: Argument 't' of 'inrval_set' with PASS(t) at (1)
must be of the derived-type 'inrset'
lib/interval.f:55:11:
Procedure :: eptset => inrval_set
1
Error: Argument 't' of 'inrval_set' with PASS(t) at (1)
must be of the derived-type 'interval'
这里是Interval 派生类型
Type Interval
Real (Real32) :: inf, sup
Contains
Procedure :: eptset => inrval_set
End Type Interval
这是Intrset 派生类型
Type Inrset
Integer (Int32) :: inf, sup
Contains
Procedure :: eptset => inrval_set
End Type Inrset
这应该是设置inf和sup的通用子程序。
Subroutine inrval_set &
( &
t, inf, sup &
)
Class (*), Intent (InOut) :: t
Class (*), Intent (In) :: inf, sup
!!$--------------------------------------------------
!!$ Sets t% inf = inf; t% sup = sup
Select Type (t)
Type Is (Interval)
Call numtrf (t% inf, inf)
Call numtrf (t% sup, sup)
Type Is (Inrset)
Call numtrf (t% inf, inf)
Call numtrf (t% sup, sup)
End Select
End Subroutine inrval_set
【问题讨论】:
-
您想知道为什么您尝试做的事情是错误的,还是另一种方法来做您想做的事情?
-
我正在寻找一种可行的方法。我已经为每种有效的类型设置了单独的例程。不过,这将有助于理解这段代码发生了什么。
-
要求我对每种情况都有单独的子例程。有没有好的解决方法,还是我必须重新考虑方法?
-
好吧,如果你有不同的类型,你需要两个不同的类型绑定过程,每个都有正确的传递虚拟参数。这就是错误所说的。如何最好地设计你的程序是一个不同的问题。
标签: fortran derived-types