简体   繁体   English

传递多态参数时,泛型没有特定功能

[英]No specific function for generic when passing a polymorphic argument

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

The functions as defined as follows for output as Int8, Int16, Int32, Int64, Real32, Real64, Real128. 对于输出为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

I am getting error 我遇到错误

There is no specific function for the generic 'numd' at (1) 

when calling numd in the following subroutine 在以下子例程中调用numd时

Subroutine opscanc (ct)
  Class (*), Intent (Out) :: ct
  ct = numd (5, mold=ct)
End Subroutine opscanc

How can I solve this problem? 我怎么解决这个问题?

The second actual argument ( mold=ct ) in the call to numd in the opscanc subroutine has a declared type that is unlimited polymorphic. 第二实际参数( mold=ct在呼叫)到numdopscanc子程序具有声明的类型是无限多态的。 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. 无限多态实际参数与具有某种已声明类型的虚拟参数在类型上不兼容,因此没有匹配的特定过程要调用。

(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.) (这里的比较方向很重要-具有某种声明类型的实际参数与无限多态的虚拟参数兼容-因此,默认整数文字常量5可以与无限多态的第一个虚拟参数相关联。)

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). 您要么需要提供这样一个匹配的特定过程,要么在opscanc内使用SELECT TYPE构造,以通过声明的类型(其动态类型(或其动态类型的父类型))访问ct提名的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将特定的类参数传递给 Java 泛型函数 - Passing a specific class argument to a Java Generic Function 快速将通用类作为参数传递给函数 - Passing generic Class as argument to function in swift 使用通用数据类型参数将数组传递给函数 - Passing array to function with generic data type argument 具有特定泛型类型参数的泛型 function 的参数类型,在 typescript - Parameters type of a generic function with specific generic type argument, in typescript 将枚举类型作为通用参数传递给 swift 2.2 iOS 中的函数 - Passing An Enum Type As An Generic Argument To a Function in swift 2.2 iOS 在将对象作为通用参数传递时如何使用对象的基础类型 - How to use the underlying type of an object when passing it as a generic argument 传递通用类 <T> 作为一个论点 - Passing a generic Class<T> as an argument 将泛型参数传递给具有特定继承的函数 - Passing a generic parameter into a function which has a specific inheritance TypeScript:多态 this 并推断通用 function 参数 - TypeScript: Polymorphic this and inferring generic function parameter TypeScript通用函数-为数组应用函数时出现“参数不可分配错误” - TypeScript Generic Function - “Argument not assignable error” when applying function for array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM