Fortran 2003 中的内在赋值和多态性 [英] Intrinsic Assignment and Polymorphism in Fortran 2003
问题描述
我尝试向这个模块,由 @VladimirF 编写,在 Fortran 2003 中实现了一个通用链表.我希望能够输出为方便起见,将列表的内容作为一个数组,所以我在一个名为 lists.f90
的文件中的列表模块中添加了以下过程:
I tried adding a procedure to this module, written by @VladimirF, that implements a generic linked list in Fortran 2003. I wanted to be able to output the contents of the list as an array for convenience, so I added the following procedure to a lists module in a file called lists.f90
:
subroutine list_as_array(self, arrayOut)
class(list),intent(inout) :: self
class(*),dimension(1:self%length),intent(out) :: arrayOut
integer :: i
type(list_node), pointer :: nodeIter
nodeIter = self%first
do i = 1,self%length
arrayOut(i) = nodeIter%item ! <---ERROR here
if (i<self%length) then
nodeIter = nodeIter%next
end if
end do
end subroutine list_as_array
ifort 18.0.0
给出以下错误:
lists.f90(324): error #8304: In an intrinsic assignment statement, variable shall not be a non-allocatable polymorphic. [ARRAYOUT]
arrayOut(i) = nodeIter%item
------^
我是 F2003+ 中的多态性新手,所以我不理解错误消息或其上下文.出了什么问题,如何解决?
I'm new to polymorphism in F2003+, so I do not understand the error message or its context. What's wrong, and how can it be fixed?
推荐答案
错误信息就是它所说的意思.描述内在赋值语句的 Fortran 2008 标准说:如果变量是多态的,它应该是可分配的,而不是 coarray"arrayOut 是 CLASS(*)
,它是多态的.只能分配可分配的多态.
The error message means what it says. The Fortran 2008 standard, describing the intrinsic assignment statement, says: "if the variable is polymorphic it shall be allocatable and not a coarray" arrayOut is CLASS(*)
, which makes in polymorphic. Only allocatable polymorphics can be assigned to.
至于如何解决",这需要更多的上下文.
As to "how to fix it", that would need some more context.
这篇关于Fortran 2003 中的内在赋值和多态性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!