简体   繁体   中英

Extend extended type

I want to extend a Fortran type that already extends a type. I know that when I have an extended type I can write

type o1
...
type, extends(o1) :: o2
...

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

How does this work when I have a third type that extends o2 ? Is this possible?

Yes. Restating the code and renaming for clarity:

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.    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM