我想使用函数的泛型名称来重载'*‘运算符,如下例所示:
interface scala
module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
module procedure :: scala
end interface operator(*)
但是,使用gfortran进行编译时,我得到:
Error: Procedure 'scala' in intrinsic '*' operator at (1) is neither function nor subroutine
有什么转机吗?
发布于 2017-05-25 13:55:35
必须用特定的函数重载
interface scala
module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
module procedure :: scalapr, scalarp
end interface operator(*)
泛型不是模块过程,因此不能出现在module procedure
中。
也只有procedure
,但这在这里没有帮助。它适用于不是来自当前模块的过程。但不管怎样,通用接口块中的函数必须是特定函数。
请参阅Fortran 2008 12.4.3.4 Generic interfaces
1通用接口块为接口块中的每个过程指定一个通用接口。PROCEDURE语句列出具有此通用接口的过程指针、外部过程、伪过程或模块过程。..。
根据7.1.6:
5 A function defines the binary operation x1 op x2 if
(2) either
(a) a generic interface (12.4.3.2) provides the function with a generic-spec of OPERATOR (op),
or
(b) there is a generic binding (4.5.5) in the declared type
因此,上面的规则和约束一样适用
过程名(
C1207,R1206)过程名应该是具有显式接口的非内部过程。
通用名称不符合C1207。
https://stackoverflow.com/questions/44173079
复制相似问题