gpt4 book ai didi

fortran - 是否可以在 Fortran 2003 中模拟混合的抽象/延迟和常规过程?

转载 作者:行者123 更新时间:2023-12-04 03:05:20 26 4
gpt4 key购买 nike

当我尝试在一种抽象类型中混合常规过程和延迟过程时,gfortran 对常规过程的任何调用都犹豫不决:
“错误:在 (1) 处的类型绑定(bind)过程调用的基础对象是抽象类型‘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 以便我可以同时拥有抽象的延迟过程和常规的实例化过程?

最佳答案

不。

有一个简单的解决方案 - 替换 call this%tBody%init(...)call new_Body(...) (您可能需要进行适当的可访问性更改)。

可能是微弱的合理化 - 您没有根据引用的类型解析过程(因为这是硬编码的),所以不要使用类型绑定(bind)过程语法。

在某些情况下,另一种解决方案是进一步拆分类型层次结构,以便抽象类型 tBody 有一个非抽象父级,它承载“非延迟”过程的初始实现。

关于fortran - 是否可以在 Fortran 2003 中模拟混合的抽象/延迟和常规过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12523727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com