因为似乎没有人知道答案,我也不知道如何解决这个问题
类型
我把这个“解决方法”贴在这里,以防有人有同样的问题。我只是把作业重载放到一个单独的模块中
使用
module overload
implicit none
public assignment(=)
interface assignment(=)
module procedure equalAssignmentReal
module procedure equalAssignmentInteger
!! additional procedures for character, logical if neccessary
end interface
contains
subroutine equalAssignmentReal(lhs, rhs)
implicit none
real, intent(out) :: lhs
class(*), intent(in) :: rhs
select type(rhs)
type is (real)
lhs = rhs
end select
return
end subroutine equalAssignmentReal
subroutine equalAssignmentInteger(lhs, rhs)
implicit none
integer, intent(out) :: lhs
class(*), intent(in) :: rhs
select type(rhs)
type is (integer)
lhs = rhs
end select
return
end subroutine equalAssignmentInteger
end module overload
module assignment
implicit none
public find
public par1
real :: par1
integer :: par2
contains
subroutine init
use overload
implicit none
par1 = find('real')
par2 = find('integer')
return
end subroutine init
function find(in) result(out)
implicit none
character(len=*), intent(in) :: in
class(*), allocatable :: out
if ( in == 'real' ) then
allocate(out, source=1.)
else if ( in == 'integer' ) then
allocate(out, source=2)
end if
return
end function find
end module assignment
program test
use assignment
implicit none
call init
print *, "par1 = ", par1
print *, "par2 = ", par2
end program test