【问题标题】:Can Fortran pointer assignment be overloaded through a type-bound generic procedure?Fortran 指针赋值可以通过类型绑定的泛型过程重载吗?
【发布时间】:2013-11-19 19:54:05
【问题描述】:

是否可以重载 Fortran 中的指针赋值?即给定一个类型

Module test
type :: pointerType
    real, pointer :: value
contains
    generic :: assignment(=>) => ptToValue !This is not legitimate syntax, (I've tried it using ifort) but does suggest the intent of question
    ...
end type

contains

subroutine ptToValue(self,other)
    type(pointerType), intent(inout) :: self
    real, target, intent(in) :: other
    self%value=>other
    end subroutine
end module

你可以创建一个该类型的数组并像这样关联元素

...
type(pointerType), dimension(50) :: example
real, target :: realvalue
...
example(3)=>realvalue

而不是这样

...
example(3)%value=>realvalue

【问题讨论】:

    标签: pointers fortran operator-overloading


    【解决方案1】:

    没有。

    相反,只需直接或通过绑定调用子例程。如果您的编译器支持 F2008 的相关部分,请考虑将另一个参数设为指针。

    【讨论】:

    • 多么令人失望。 IanH - 你非常乐于助人,我非常感激。
    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多