Fortran未解析的模块过程规范名称

时间:2014-04-22 15:57:25

标签: function fortran overloading fortran90 subroutine

我有一个示例代码来测试我对Fortran 90中重载子例程的理解。这是我的例子:

   module testint_mod
    use constants
    implicit none

    private :: testvReal
    private :: testvdpn

   interface testv
     module procedure testvReal
     module procedure testvdpn
   end interface
   contains

   subroutine testvReal(vR)
     implicit none
     real,intent(in) :: vR
     write(*,*) vR
   end subroutine

   subroutine testvdpn(vdpn)
     implicit none
     real(kind=dpn),intent(in) :: vdpn
     write(*,*) vdpn
   end subroutine

   end module testint_mod


   program testintmain
    use constants
    use testint_mod
   implicit none
   real :: r
   real(kind=dpn) :: d
   integer :: i

   interface testv
    module procedure testvdpn
   end interface

   r = 2.0
   d = dble(4.0)
   call testv(r)
   call testv(d)

   end program testintmain

其中常量包括:整数,参数dpn = selected_real_kind(14)

我收到错误:

   testint_main.F(10) : Error: Unresolved MODULE PROCEDURE specification name.   [T
   ESTVDPN]
           module procedure testvdpn
   -------------------------^

我做错了什么?使用selected_real_kind()重载函数是不允许的?我感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

interface testv主程序中的规范存在问题:编译器抱怨testvdpn无法在主程序中解析 - 并且该名称确实无法公开访问。此外,testv已经可以通过使用定义它的模块testint_mod的关联来访问。应删除这三行。

回答稍后提出的问题

  

是否不允许使用selected_real_kind()重载函数?

如果泛型集中的两个过程仅通过真实参数的kind类型参数区分,那么一个(或多个)来自selected_real_kind结果是无关紧要的。但是,应该注意类型参数确实是不同的。例如,可能是示例的selected_real_kind(14)返回与默认真实相同的类型。不允许这种情况和类似情况。虽然编译器肯定会呻吟。

另请注意,为了完整性,对于函数(而不是问题的子例程),消歧必须完全取决于函数的参数,而不是结果。< / p>

相关问题