1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
module class_40_mod
type :: AbsNestedType
contains
procedure :: abs_nested_method
end type AbsNestedType
type, public :: AbsType
class(AbsNestedType), allocatable :: nested_obj
contains
procedure :: abs_method
end type AbsType
type :: Wrapper
class(AbsType), allocatable :: obj
type(AbsType) :: t_obj
end type Wrapper
type :: Client
type(Wrapper) :: wrapped
contains
procedure :: caller
end type Client
contains
subroutine caller(self)
class(Client), intent(in) :: self
type(Client) :: type_s
integer :: i
i = self%wrapped%obj%abs_method(42)
if (i /= 1) error stop
i = 0
i = self%wrapped%obj%nested_obj%abs_nested_method(101)
if (i /= 1) error stop
i = 0
i = type_s%wrapped%t_obj%abs_method(42)
if (i /= 1) error stop
end subroutine caller
integer function abs_method(self, val)
class(AbsType), intent(in) :: self
integer, intent(in) :: val
print *, "abs_method called"
if (val /= 42) error stop
abs_method = 1
end function abs_method
integer function abs_nested_method(self, val)
class(AbsNestedType), intent(in) :: self
integer, intent(in) :: val
print *, "abs_nested_method called"
if (val /= 101) error stop
abs_nested_method = 1
end function abs_nested_method
end module class_40_mod
program class_40
use class_40_mod
class(Client), allocatable :: var
allocate(var)
allocate(var%wrapped%obj)
allocate(var%wrapped%obj%nested_obj)
call var%caller()
end program class_40
|