此类型绑定的泛型子例程调用没有匹配的特定子例程 [英] There is no matching specific subroutine for this type bound generic subroutine call
问题描述
我有一个在通用过程(GetValue)下具有两个绑定过程(GetAsScalar& GetAsList)的类型:
I have a type with two bound procedures (GetAsScalar & GetAsList) under a generic procedure (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对象存储一个字符串.
Internally, the TKeyword object stores a string.
如果我尝试通过以下方式使用它(波纹管),则会出现编译错误:此类型绑定的泛型子例程调用没有匹配的特定子例程"
If I try to use it in the following way (bellow), I get a compilation error: "There is no matching specific subroutine for this type bound generic subroutine call"
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并将其公开,则以下代码将按预期工作:
If I remove the GetASScalar from the generic association and make it public, the following code works as expected:
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例程.
When passing a scalar (integer, real, character, etc), the GetAsScalar routine is called without problems.
我想知道为什么会这样.我在通用"中缺少什么,使编译器无法识别通用下的子例程?有办法使这项工作吗?与常规签名有关吗?
I would like to know why this is happening. What am I missing in this "generic thing" that makes the compiler unable to recognize my subroutine under the generic? There is a way to make this work? Would be something related with the routine signature?
我正在使用Intel Fortran 15.0.1.148
I'm using Intel Fortran 15.0.1.148
推荐答案
Acoording to answers in the intel fortran forum (https://software.intel.com/en-us/forums/topic/537784#comment-1809520), this code should work and the compiler error is probably a small bug in the compiler.
史蒂夫·莱昂内尔(Intel)将问题升级了.
An issue was escalated by Steve Lionel (Intel).
谢谢.
这篇关于此类型绑定的泛型子例程调用没有匹配的特定子例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!