Fortran 2003延迟绑定过程的实现是否需要相同的参数? [英] Does Fortran 2003 implementation of deferred bound procedure requires same argument?

查看:117
本文介绍了Fortran 2003延迟绑定过程的实现是否需要相同的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在模块内部创建抽象类型

I tried to create inside a module an abstract type

type, abstract :: AbsType
    contains
     procedure (Compute_AbsSize), deferred :: AbsSize
end type AbsType
abstract interface
    function Compute_AbsSize(this)
        import AbsType
        double precision Compute_AbsSize
        class(AbsType)::this
    end function Compute_AbsSize
end interface

type, extends(AbsType) :: ConcrType
     type(Var), dimension(4) :: Nodes ! coming from a module
    contains
     procedure :: AbsSize => ConcrTypeSize
end type ConcrType

contains

function ConcrTypeSize(this)
        double precision ConcrTypeSize
        class (ConcrType):: this        ! 
end function ConcrTypeSize

事实证明,如果我写

function ConcrTypeSize(TheConcrType)
        double precision ConcrTypeSize
        class (ConcrType):: TheConcrType        ! 
end function ConcrTypeSize

编译器(gcc)抱怨TheConcrType应该具有与延迟函数变量相同的名称.我找不到此信息,有人知道我为什么必须这样做,这是正确的吗?

the compiler (gcc) complains that TheConcrType should have the same name of the variable of the deferred function. I could not find this information, does anybody know why I have to do this, and is this correct?

编辑:我将问题的最后一部分移至 此新问题

Edit: I moved the last part of the quetion to this new question

推荐答案

扩展中覆盖父类型中特定绑定的特定绑定必须具有名称和特征匹配的伪参数,并禁止传递的参数的类型(如果有).在F2008标准第4.5.7.3节中对此进行了解释(F2003中的类似词语).

A specific binding in an extension that overrides a specific binding in the parent type must have dummy arguments that match in name and characteristics, bar the type of the passed argument, if any. This is explained in the F2008 standard in section 4.5.7.3 (similar words in F2003).

因此,编译器的抱怨是正确的.请记住,在引用过程时可以使用哑元参数的名称,也可以在PASS属性中使用该参数进行绑定.在这种情况下,参数名称不匹配是没有道理的.

The compiler is therefore correct to complain. Remember that the name of a dummy argument can be used when the procedure is referenced, and may also be used in the PASS attribute for the binding. A mismatch in argument names doesn't make sense in those contexts.

关于您的最后一段,我不清楚您想要的是什么,或者与问题的上一部分有什么关系.但是,请注意,组件可以分配.具有可分配组件的每个类型的对象都可以将组件分配给不同的大小.同样,虽然绑定过程中的伪自变量必须具有匹配的特征,并且伪自变量的特征是其形状,但是该形状可以假定为形状.

With respect to you last paragraph it is not clear to me exactly what you want, or how that relates to the previous part of the question. However, note that components can be allocatable. Each object of type with an allocatable component could have the component allocated to a different size. Similarly, while dummy arguments in bound procedures must have matching characteristics, and a characteristic of a dummy argument is its shape, that shape could be assumed shape.

这篇关于Fortran 2003延迟绑定过程的实现是否需要相同的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆