Home > Software design >  How to make a type-bound polymorphic pointer point to an extended type, using a parent type-bound pr
How to make a type-bound polymorphic pointer point to an extended type, using a parent type-bound pr

Time:09-17

I am not sure if I wrote the question title right, but I did a MWE to explain me better what I would like to do:

module prueba

type    :: basic
  class(basic),pointer  :: myself => null()
  contains
  procedure :: hello => basic_hello
end type
 
type,extends(basic)    :: complicated
  contains
  procedure :: hello => complicated_hello
end type

contains

subroutine basic_hello(a)
class(basic), target  :: a
a%myself=>a       ! <----- XXX
print *, 'I am basic'
end subroutine
 
subroutine complicated_hello(a)
class(complicated), target  :: a
call a           
  • Related