2014-09-12 66 views
1

我需要声明一个类型a,其中包含一个类型为a的元素数组的成员。Fortran:包含这种类型元素数组的成员的类型

我的想法是这样的:

type:: a 
type(pta), dimension(:), allocatable:: array 
end type a 

type:: pta 
class(a), pointer:: p 
end type pta 

是什么做的,在Fortran语言的正确方法?

回答

2

你可以简单地在你的类型中插入一个指针。这看起来像:

type a 
    type(a), dimension(:), pointer :: array 
end type 

然后,您可以简单地分配数组在其所需的大小。

4

或者让自己的Fortran 2008编译器,你可以写

type :: a 
    type(a), dimension(:), allocatable :: array 
end type 

虽然赞赏这个答案的原始形式囊括了代表我要指出的是,据我所知,只有IBM和Cray Fortran编译器目前支持新兴标准的这一特性。 @ Stefan的答案适用于当前所有广泛使用的Fortran编译器。