问题描述
当我尝试将常规过程和递延过程混合在一种抽象类型中时,gfortran会在常规过程的任何调用时都失败:错误:在(1)处进行类型绑定过程调用的基础对象的类型为'tbody',为ABSTRACT类型."
When I try to mix both regular procedures and deferred procedures in one abstract type, gfortran balks at any invocation of the regular procedures:" Error: Base object for type-bound procedure call at (1) is of ABSTRACT type 'tbody' "
type, abstract :: tBody
private
...
contains
procedure :: init => new_Body
...
procedure (contained), deferred :: PointIn
end type tBody
abstract interface
logical(LGT) pure function contained( Body, Point )
import :: tBody, tAffinePoint, LGT
class(tBody), intent(IN) :: Body
type(tAffinePoint), intent(IN) :: Point
end function contained
end interface
subroutine newCuboid( this, ... )
class(tCuboid), intent(OUT) :: this
...
call this%tBody%init( ... )
.... [gfortran halts here]
end subroutine newCuboid
是否可以安排类型tBody以便我可以同时拥有抽象的延迟过程和常规的实例化过程?
Is there a way to arrange the type tBody so that I can have both abstract, deferred procedures and regular, instantiated procedures?
推荐答案
否.
有一个简单的解决方案-将 call this%tBody%init(...)
替换为 call new_Body(...)
(您可能需要进行适当的可访问性更改).
There's a simple solution - replace call this%tBody%init(...)
with call new_Body(...)
(you may need to make appropriate accessibility changes).
合理化可能微不足道-您不是基于引用的类型来解析过程(因为它是硬编码的),因此请不要使用类型绑定过程的语法.
Possibly feeble rationalisation - you are not resolving the procedure on the basis of the type of the reference (because that's hard coded), so don't use type bound procedure syntax.
在某些情况下,另一种解决方案是进一步拆分类型层次结构,以使抽象类型tBody具有非抽象父级,该父级承载未延迟"过程的初始实现.
Another solution in some cases is to split the type hierarchy further, so that the abstract type tBody has a non-abstract parent that hosts the initial implementation of the "not deferred" procedures.
这篇关于是否可以在Fortran 2003中模拟抽象/延迟和常规过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!