此类型绑定通用子例程调用没有匹配的特定子例程

时间:2014-12-30 12:32:17

标签: generics fortran procedure fortran2003

我有一个在通用程序(GetValue)下有两个绑定程序(GetAsScalar& GetAsList)的类型:

type, extends(TObject)  ::  TKeyword
    character(len=:), allocatable               ::  fValue

contains
    procedure, private                          ::  GetAsScalar
    procedure, private                          ::  GetAsList        

    generic                                     ::  GetValue    =>  &
                                                    GetAsScalar,    &
                                                    GetAsList
end type TKeyword

例程签名是:

subroutine GetAsScalar (this, value, status)
    !Arguments-------------------------------------------------------------
    class(TKeyword)                                 ::  this
    class(*), target                                ::  value
    logical, optional                               ::  status

    !...
end subroutine GetAsScalar

subroutine GetAsList (this, value, status)
    !Arguments-------------------------------------------------------------
    class(TKeyword)                                 ::  this
    class(*), pointer                               ::  value(:)
    logical, optional                               ::  status

    !...
end subroutine GetAsList

在内部,TKeyword对象存储一个字符串。

如果我尝试以下列方式使用它(下图),我得到一个编译错误:“此类型绑定通用子例程调用没有匹配的特定子例程”

class(TKeyword), pointer :: key
class(*), pointer :: p(:)
allocate (integer::p(3))

!Code to read instantiate the TKeyword object

call key%GetValue(p, status)

select type (p)
type is (integer)
    write (*,*) p
end select

如果我从通用关联中删除GetASScalar并将其公开,则以下代码按预期工作:

class(TKeyword), pointer :: key
class(*), pointer :: p(:)
allocate (integer::p(3))

!Code to read instantiate the TKeyword object

call key%GetAsList(p, status)

select type (p)
type is (integer)
    write (*,*) p
end select

传递标量(整数,实数,字符等)时,会调用GetAsScalar例程而不会出现问题。

我想知道为什么会这样。我在这个“通用的东西”中缺少什么使编译器无法识别泛型下的子程序?有一种方法可以使这项工作?会与常规签名有关吗?

我正在使用英特尔Fortran 15.0.1.148

1 个答案:

答案 0 :(得分:0)

根据intel fortran论坛(https://software.intel.com/en-us/forums/topic/537784#comment-1809520)中的答案,此代码应该有效,编译器错误可能是编译器中的一个小错误。

Steve Lionel(英特尔)提出了一个问题。

感谢。