微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未按预期方式调用Fortran最终程序

如何解决未按预期方式调用Fortran最终程序

我有一个具有其他类型的可分配数组的容器类型。当对容器类型调用最终过程并释放了可分配数组时,它不会触发数组中每个对象的最终过程,这正是我所期望的。下面是一些示例代码,演示了我的问题。

Module AType
implicit none

Type A_T
    real :: x
End Type A_T

Type Inner_T
    Class(A_T),allocatable :: A
contains
    final :: inner_destroy
End Type Inner_T

Type Container_T
    type(Inner_T),dimension(:),allocatable :: inners
contains
    final :: container_destroy
End Type Container_T
  
contains

subroutine inner_destroy(this)
    type(Inner_T),intent(inout) :: this
    if(allocated(this%A)) deallocate(this%A)
end subroutine inner_destroy

subroutine container_destroy(this)
    type(Container_T),intent(inout) :: this
    if(allocated(this%inners)) deallocate(this%inners)
end subroutine container_destroy

End Module AType

虽然Container_T移出作用域时将调用容器final方法,但不会从包含数组的释放中调用Inner_T的final方法。是否有方便的方法来触发此最终方法,还是必须为Inner_T创建包装类型?还是这种不正确的行为?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。