Neil Carlson wrote:
> It seems that
> it is not possible to have a polymorphic-type array with each element
> a different dynamic type. Is that correct?
That is correct---all members of an array must have the same type.
Changing this would have required big changes to Fortran (think of
array statements and what that would mean if each element had a
different dynamic type, for example). Also, it is more efficient, since
only one type descriptor is needed per array.
> If so, then what is the
> best way to achieve the effect. Is it to adapt the array-of-pointers
> technique by introducing a type that boxes a pointer to the
> polymorphic type, and then declaring an array of the box type and
> allocating each pointer to the desired dynamic type?
Yes, you can make an array of a derived type with a CLASS(*) pointer or
allocatable component, for example.
Best,
Aleks
|