0
我想扩展一个已经扩展类型的Fortran类型。我知道,当我有一个扩展类型,我可以写扩展扩展类型
type o1
...
type, extends(o1) :: o2
...
type(Object1) :: o1
allocate(o2::o1)
如何做这项工作时,我有一个扩展o2
第三种类型?这可能吗?
我想扩展一个已经扩展类型的Fortran类型。我知道,当我有一个扩展类型,我可以写扩展扩展类型
type o1
...
type, extends(o1) :: o2
...
type(Object1) :: o1
allocate(o2::o1)
如何做这项工作时,我有一个扩展o2
第三种类型?这可能吗?
是的。重述代码和重命名的清晰度:
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.
啊谢谢,应该想到这一点。 – 2013-02-16 14:18:24