On 11/11/21 13:30, rbader wrote:
>
> It is not possible to specify default initialization of the base type's component in an extension.
> However, if only the extended type is visible in user code, why not use two differently initialized base types,
> with the same name for the type component?
Reinhold
do you intend something like (omitting lot of details)
module base_mod
providing base type definition and methods acting on base type (say for
example set, get, print).
This module will be never seen by the code end-user (that will interact
only with what is exported by modules dt1_mod and dt2_mod).
Everything is public, so that it may be freely accessed inside dt1_mod
and dt2_mod
module dt1_mod
use base_mod
type :: dt1_t
private
type(base_t) :: base_component = dt1 default initialization
!-- no dt1-specialized type component
end type dt1_t
public:: dt1_t, "common" methods, dt1-specialized methods
contains
"common" methods, basically written on the spirit of
subroutine get_dt1 ( (instance, stuff)
type(dt1_t), intent(in) :: instance
.. intent(out) :: stuff
call get_base (dt1%base_component, stuff)
!-- no dt1-specialized components, so nothing else to do
end subroutine get_dt1
..
dt1-specialized methods (a fair number of procedures)
end module dt1_mod
module dt2_mod
use base_mod
type :: dt2_t
private
type(base_t) :: base_component = dt2 default initialization
!-- no dt2-specialized type component
end type dt2_t
public:: dt2_t, "common" methods, dt2-specialized methods
contains
"common" methods, basically written on the spirit of
subroutine get_dt2 ( (instance, stuff)
type(dt2_t), intent(in) :: instance
.. intent(out) :: stuff
call get_base (dt2%base_component, stuff)
!-- no dt2-specialized components, so nothing else to do
end subroutine get_dt2
..
dt2-specialized methods (a fair number of procedures)
end module dt2_mod
Well, that's a possibility, thanks. I have to say that I do not like it
that much, but, as we say here in Italy "bisogna fare di necessita'
virtu'" (= that may be very freely translated as "catch as you can").
Thanks
Gigi