我想使用一个运算符 .ef。,但运算符不接受可选参数。是否有可能保留我的功能,并且能够让操作员也工作?
模块核心隐含无 接口操作符(.ef。)模块过程fes 结束接口操作符(.ef。) 包含 功能fes& (& nm,wn& )& 结果(位于) 逻辑位置字符(Len = *),意图(In):: nm 字符(Len = *),意图(In),Optional :: wn End FunctionGfortran正在返回以下问题:
lib / scriptus / core.f:62:0: 函数fes& amp ; 1 错误:在(1)操作员界面的第二个参数不能是可选的解决方案
您不允许为定义的操作提供可选参数。 Fortran 2008,Cl。 12.4.3.4.2。说:
...虚拟参数应该是非可选的虚拟数据对象... blockquote>这是编译器在发出错误时引用的内容:
错误: (1)处的操作员界面的第二个参数不能是可选的
注意:您可以拥有可选参数的过程,并且它们可以显示在模块中,但它们不能在带有操作符关键字的接口块中引用。你的函数 fes 看起来不错,这不是问题。你的问题是将操作符映射到函数的接口块。
I want to use an operator .ef. however the operator does not accept optional arguments. Is it possible to keep the my function and be able to have the operator working too?
Module Core Implicit None Interface Operator (.ef.) Module Procedure fes End Interface Operator (.ef.) Contains Function fes & ( & nm, wn & ) & Result (located) Logical :: located Character (Len=*), Intent (In) :: nm Character (Len=*), Intent (In), Optional :: wn End FunctionGfortran is returning the following problem
lib/scriptus/core.f:62:0: Function fes & 1 Error: Second argument of operator interface at (1) cannot be optional解决方案
You are not allowed to have optional arguments to defined operations. Fortran 2008, Cl. 12.4.3.4.2. says:
1 ... The dummy arguments shall be nonoptional dummy data objects ...
This is what your compiler is referencing when it emitted the error:
Error: Second argument of operator interface at (1) cannot be optional
Note: you can have procedures with optional arguments and they can appear in modules, but they cannot be referenced in interface blocks with the operator keyword. Your function fes looks fine and it is not the problem. Your problem is the the interface block mapping an operator to the function.
更多推荐
带有可选参数的Fortran函数
发布评论