Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用泛型函数重载Fortran运算符_Fortran_Operator Overloading_Gfortran - Fatal编程技术网

使用泛型函数重载Fortran运算符

使用泛型函数重载Fortran运算符,fortran,operator-overloading,gfortran,Fortran,Operator Overloading,Gfortran,我想使用函数的通用名称重载“*”运算符,如下例所示: interface scala module procedure :: scalapr,scalarp end interface scala interface operator(*) module procedure :: scala end interface operator(*) 但是,使用gfortran编译时,我得到: Error: Procedure 'scala' in intrinsic '*' opera

我想使用函数的通用名称重载“*”运算符,如下例所示:

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

有什么转机吗?

您必须用特定的函数重载

interface scala
    module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
   module procedure :: scalapr, scalarp
end interface operator(*)
泛型不是模块过程,因此它不能出现在
模块过程中

还有一个
过程
,但在这里没有帮助。它适用于不来自当前模块的程序。但是无论如何,通用接口块中的函数必须是特定函数

参见Fortran 2008
12.4.3.4通用接口:

1通用接口块为以下各项指定通用接口: 接口块中的过程。过程语句列出了 过程指针、外部过程、伪过程或模块 具有此通用接口的过程

根据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。

必须使用特定函数重载

interface scala
    module procedure :: scalapr,scalarp
end interface scala
interface operator(*)
   module procedure :: scalapr, scalarp
end interface operator(*)
泛型不是模块过程,因此它不能出现在
模块过程中

还有一个
过程
,但在这里没有帮助。它适用于不来自当前模块的程序。但是无论如何,通用接口块中的函数必须是特定函数

参见Fortran 2008
12.4.3.4通用接口:

1通用接口块为以下各项指定通用接口: 接口块中的过程。过程语句列出了 过程指针、外部过程、伪过程或模块 具有此通用接口的过程

根据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。

这在编译器消息中是明确的。我的问题是是否有其他选择。不,没有。我就是这么说的。(这里有那么多人不阅读或不试图理解编译器消息,你会感到惊讶。)从编译器消息中可以清楚地看出这一点。我的问题是是否有其他选择。不,没有。我就是这么说的。(这里有这么多人不阅读或不试图理解编译器消息,你会感到惊讶。)