问题描述
我为以下功能创建了一个界面
I have created an interface for the following functions
Interface numd
Module Procedure :: numcl_int8, numcl_int16
Module Procedure :: numcl_int32, numcl_int64
Module Procedure :: numcl_real32, numcl_real64
Module Procedure :: numcl_real128
End Interface numd
如下定义的功能,用于输出为Int8,Int16,Int32,Int64,Real32,Real64,Real128.
The functions as defined as follows for output as Int8, Int16, Int32, Int64, Real32, Real64, Real128.
Function numcl_int8 (t, mold) Result (b)
Integer (Int8) :: b
Class (*), Intent (In) :: t
Integer (Int8), Intent (InOut) :: mold
End Function numcl_int8
我遇到错误
There is no specific function for the generic 'numd' at (1)
在以下子例程中调用numd时
when calling numd in the following subroutine
Subroutine opscanc (ct)
Class (*), Intent (Out) :: ct
ct = numd (5, mold=ct)
End Subroutine opscanc
我该如何解决这个问题?
How can I solve this problem?
推荐答案
在opscanc
子例程中调用numd
的第二个实际参数(mold=ct
)具有声明的类型,该类型是无限多态的.根据特定过程的接口示例,通用接口中的特定过程都没有第二个伪参数的类型为无限多态.
The second actual argument (mold=ct
) in the call to numd
in the opscanc
subroutine has a declared type that is unlimited polymorphic. Based on your example of the interface of the specific procedures, none of the specific procedures in the generic interface have the type of the second dummy argument as unlimited polymorphic.
无限多态实际参数与具有某种已声明类型的虚拟参数在类型上不兼容,因此没有匹配的特定过程要调用.
An unlimited polymorphic actual argument is not type compatible with a dummy argument that has some declared type, so there is no matching specific procedure to call.
(比较的方向在这里很重要-具有某种声明类型的实际参数与无限多态的虚拟参数兼容-因此默认整数文字常量5
可以与第一个虚拟参数相关联是无限多态的.)
(The direction of the comparison is important here - an actual argument that has some declared type is compatible with a dummy argument that is unlimited polymorphic - hence the default integer literal constant 5
can be associated with the first dummy argument that is unlimited polymorphic.)
您需要提供这样一个匹配的特定过程,或者在opscanc
中使用SELECT TYPE构造来通过声明的类型(其动态类型(或其动态类型的父类型))访问由ct
提名的对象.类型).
You either need to provide such a matching specific procedure, or use a SELECT TYPE construct inside opscanc
to access the object nominated by ct
via a declared type that is its dynamic type (or a parent type of its dynamic type).
这篇关于传递多态参数时,没有针对泛型的特定函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!