pointers - Pointing to a object's type variable - Fortran -
as understand, user-derived type's definition can't contain target
attributes. e.g., isn't allowed:
type testtype integer, target :: t end type
however, it's fine them pointer:
type testtype2 integer, pointer :: p end type
my question is, then, how can 1 use pointer point @ object's type variable? example, if wanted object of type(testtype2)
have p
variable point object of type(testtype)
's t
variable, how go this? example:
type(testtype) :: tt type(testtype2) :: tt2 tt%t = 1 tt%p => tt%t
thanks!
there little sense in
type testtype integer, target :: t end type
because values of type(testtype)
may come in contexts cannot target of pointer.
as @roygvib comments, have give target
attribute whole object variable:
type(testtype), target :: tt
then can make pointers of components.
i imagine 1 allow giving target attribute allocatable structure components in type declaration, not allowed. not make sense regular components.
Comments
Post a Comment