我的情況下有一個通用的程序兩個綁定程序(GetAsScalar & GetAsList)(的GetValue)一個類型沒有匹配的特定子程序:有這種類型的束縛通用子程序調用
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