本帖最后由 kyra 于 2020-8-11 08:44 编辑
[Fortran] 纯文本查看 复制代码 module m_haha
implicit none
type t_haha
integer :: a
contains
procedure :: test1
procedure :: test2
procedure :: test3
generic :: test=>test1,test2,test3
end type t_haha
contains
subroutine test1(this,i)
implicit none
class(t_haha),intent(inout) :: this
integer,intent(in) :: i
this%a=i
return
end subroutine test1
subroutine test2(this,a)
implicit none
class(t_haha),intent(inout) :: this
integer,intent(in) :: a(0:3)
this%a=sum(a)
return
end subroutine
subroutine test3(this,a)
implicit none
class(t_haha),intent(inout) :: this
integer,intent(in) :: a(3)
this%a=sum(a)
return
end subroutine
end module m_haha
program main
use m_haha
implicit none
type(t_haha) :: one
call one%test1(1)
print*,one%a
call one%test2([0,1,2,3])
print*,one%a
call one%test3([1,2,3])
print*,one%a
end program main
使用gfotran编译报错,错误原因,test2,test3接口冲突
改用pgi编译,正常。
很迷。。。。是我对重载的理解有问题吗?
|