[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
[Fortran] 纯文本查看 复制代码
module pgi_generic
implicit none
interface test
module procedure test2
module procedure test3
end interface test
contains !------------------------------
subroutine test2(a)
implicit none
integer,intent(in) :: a(0:3)
write(*,*) a
end subroutine test2
!-----------------
subroutine test3(a)
implicit none
integer,intent(in) :: a(3)
write(*,*) a
end subroutine test3
end module pgi_generic
!---------------------------------------
program test
use pgi_generic
implicit none
integer :: a(0:3), b(3)
a = (/0, 1, 2, 3/)
b = (/4, 5, 6/)
!---> PGI compile-time error: ambiguous interface for generic procedure test
CALL test(a)
CALL test(b)
end program test