Hi there!
I wonder weather Fortran arrays can hold objects of mixed dynamic
type? Well, let me point this out by an example:
> PROGRAM MAIN
>
> TYPE, ABSTRACT :: base_typ
> END TYPE
> TYPE, EXTENDS(base_typ) :: a_typ
> INTEGER :: a
> END TYPE
> TYPE, EXTENDS(base_typ) :: b_typ
> REAL :: b
> END TYPE
> ! May hold a_typ or b_typ
> CLASS(base_typ), ALLOCATABLE :: ab_obj(:)
> ALLOCATE( ab_obj(2), source=[a_typ(1),a_typ(2)] )
> ! This makes ab_obj to be of size 2 and dynamic type a_typ
>
> DEALLOCATE( ab_obj )
> ALLOCATE( ab_obj(2), source=[b_typ(1.0),b_typ(2.0)] )
> ! Well, it could also hold b_typ
>
> DEALLOCATE( ab_obj )
> ! However, holding mixed types does not work
> ALLOCATE( ab_obj(2), source=[a_typ(1),b_typ(2.0)] )
> ! and this is exactly what I want
> ! Is there a way around? END PROGRAM
What I would like to have is that the first array element ab_obj(1) is
of dynamic type a_typ whereas ab_obj(2) is b_typ. Is there a way to
achieve this?
Thank you very much for your help.
Cheers,
Stefan
|