问题描述
我有一个具有其他类型的可分配数组的容器类型。当对容器类型调用最终过程并释放了可分配数组时,它不会触发数组中每个对象的最终过程,这正是我所期望的。下面是一些示例代码,演示了我的问题。
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 (将#修改为@)