SELECT TYPE构造中的多态性分配 [英] Polymorphism allocation in a SELECT TYPE construct
问题描述
我试图定义一个子程序来分配不同类型的数组。下面是代码的简化版本:
I am trying to define a subroutine which allocates different types of arrays. Here is a simplified version of the code:
subroutine Allocation1(Vec)
class(*), allocatable, intent(out) :: Vec(:)
select type(Vec)
type is(real(8))
allocate(Vec(10)); Vec = 0.D0
type is(complex(8))
allocate(Vec(10)); Vec = (0.D0,0.D0)
type is(integer)
allocate(Vec(10)); Vec = 0
endselect
endsubroutine Allocation1
但我有三个错误消息我不明白:
But I got three error messages that I don't understand:
error #8306: Associate name defined in ASSOCIATE or SELECT TYPE statements doesn't have ALLOCATABLE or POINTER attribute [VEC]
正如你可以看到 VEC
是一个可分配的数组,所以我不认为这个错误有意义。
As you can see VEC
is an allocatable array, so I don't think this error make sense. What does it mean, and how do I make this work?
我正在使用IVF XE 14.0.1.139。
I am using IVF XE 14.0.1.139.
推荐答案
看起来像一个编译器错误,与Gfortran和Solaris Studio一起使用。我建议您与您的官方英特尔支持联系。
Seems like a compiler bug, works with Gfortran and with the Solaris Studio. I recommend you to contact your official Intel support.
IanH指出,其他编译器可能编译错误。无论如何,无论是否符合标准,过程仍然是无用的,因为对于select类型工作,变量仍然必须已经分配,因为您的过程的实际参数必须是多态的。你不能只传递 real,allocatable
。
As IanH points out, it is possible the other compilers are in error to compile that. Anyway, be it standard conforming or not, the procedure would still be useless, because for the select type to work the variable would still have to be already allocated, because the actual argument to your procedure must be polymorphic. You cannot just pass real, allocatable
there.
这篇关于SELECT TYPE构造中的多态性分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!