【发布时间】: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