A Struct Testype2 contained the subobject of Testype1. I defined the final procedure which contain a write statement for both the two Type.
case1: I define a allocatable varaiable of testype2, after I deallocate it, the final procedure of the two type both invoked. I think this is the right result.
case2: I define a allocatable array of testype2 which contained 10 items, after I deallocate it, the testype1 final procedure was invoked 10 times, but the testype2 final procedure wasn't invoked. I don't know why.
can anybody help me? Steve~ Help~~
case1 code:
module mod1 implicit none type :: testype1 integer :: i contains procedure :: PrintTT1 Final :: FinalTT1 end type testype1 type :: testype2 type(testype1) :: tt1 contains Final :: FinalTT2 end type testype2 contains subroutine PrintTT1(this) class(testype1) :: this write(*,*) "this.x=", this.i end subroutine PrintTT1 subroutine FinalTT1(this) type(testype1) :: this write(*,*) "Final Testype1" end subroutine FinalTT1 subroutine FinalTT2(this) type(testype2) :: this write(*,*) "Final Testype2" end subroutine FinalTT2 end module mod1 subroutine TestFinal() use mod1 type(testype2), allocatable :: tt2 allocate(tt2) tt2.tt1.i = 3 call tt2.tt1.PrintTT1() deallocate(tt2) end subroutine TestFinal program main implicit none call TestFinal() end program main
case2 code:
module mod1 implicit none type :: testype1 integer :: i contains procedure :: PrintTT1 Final :: FinalTT1 end type testype1 type :: testype2 type(testype1) :: tt1 contains Final :: FinalTT2 end type testype2 contains subroutine PrintTT1(this) class(testype1) :: this write(*,*) "this.x=", this.i end subroutine PrintTT1 subroutine FinalTT1(this) type(testype1) :: this write(*,*) "Final Testype1" end subroutine FinalTT1 subroutine FinalTT2(this) type(testype2) :: this write(*,*) "Final Testype2" end subroutine FinalTT2 end module mod1 subroutine TestFinal() use mod1 type(testype2), allocatable, dimension(:) :: tt2 integer :: m allocate(tt2(10)) do m=1,10 tt2(m).tt1.i = m call tt2(m).tt1.PrintTT1() end do deallocate(tt2) end subroutine TestFinal program main implicit none call TestFinal() end program main



