首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展扩展类型

扩展扩展类型
EN

Stack Overflow用户
提问于 2013-02-16 04:30:11
回答 1查看 594关注 0票数 0

我想扩展一个已经扩展了一个类型的Fortran类型。我知道当我有一个扩展类型时,我可以写

代码语言:javascript
复制
type o1
...
type, extends(o1) :: o2
...

type(Object1) :: o1
allocate(o2::o1)

当我有第三个扩展o2的类型时,这是如何工作的?这个是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2013-02-16 04:57:27

是。为清楚起见,重复代码并重命名:

代码语言:javascript
复制
type :: t1               ! The top level parent type.
  integer :: c1          ! A component in the parent type.
end type t1

type, extends(t1) :: t2  ! An extension of t1.
  integer :: c2
end type t2

type, extends(t2) :: t3  ! A further extension of t2.
  integer :: c3
end type t3

! Declare an object of declared type t1.
class(t1), allocatable :: object

! Allocate that object, giving it a dynamic type of t3.
allocate(t3 :: object)

object%c1 = 1       ! c1 is a component of the declared type.
! Use select type or a type bound procedure to access c2 and c3.    
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14902841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档