可以通过类型绑定的通用过程来重载Fortran指针分配吗? [英] Can Fortran pointer assignment be overloaded through a type-bound generic procedure?

查看:113
本文介绍了可以通过类型绑定的通用过程来重载Fortran指针分配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Fortran中重载指针分配?即给定类型

Is it possible to overload the pointer assignment in Fortran? i.e. given a type

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

您可以创建该类型的数组并关联这样的元素

you could create an array of that type and associate elements like this

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

而不是这样

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

推荐答案

否.

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

Instead, simply invoke the subroutine directly or through a binding. If your compiler supports the relevant parts of F2008, consider making the other argument a pointer.

这篇关于可以通过类型绑定的通用过程来重载Fortran指针分配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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