Вопрос

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

It turns out that if I write

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

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

Это было полезно?

Решение

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).

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top