2014-04-22 23 views
0

我有一个示例代码测试我用Fortran 90超载子程序理解这是我的例子:Fortran的未解决的模块程序规范名称

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

interface testv主程序的规范是有问题的:编译器抱怨testvdpn不能在主程序来解决 - 也的确是没什么用这个名字公开访问。此外,testv已经可以通过使用它定义的模块testint_mod的关联来访问。这三行应该删除。

为了回答后问的问题

Is overloading a function with selected_real_kind() not allowed?

如果一套通用的两个过程是由一个真正的参数的种类参数来分辨,那么也不要紧应一个(或多个)来从selected_real_kind结果。但是,应该注意的是种类参数真的很明显。例如,该示例的selected_real_kind(14)可能会返回与默认实数相同的种类。这和类似的情况是不允许的。虽然编译器肯定会呻吟。

还要注意,为了完整性,对于功能(而非子程序的问题)消歧必须由职能的论点,而不是结果只。

+0

啊,当然,我忘了通过使用声明的访问。现在好像工作正常,谢谢! – Charlie

+0

不,函数结果的类型在通用分辨率中不起作用!只有论据是重要的。 –

+0

@VladimirF上下文应该是结果没有考虑,但我希望澄清,现在的答案。 – francescalus

相关问题