the following code compiles and runs although "a" of type "typeA" is decleared "private":
Module Mod_TypeA Type :: TypeA Private Real :: a End type TypeA End Module Mod_TypeA Module Mod_TypeB use Mod_TypeA Type :: TypeB Type(TypeA) :: TA contains Private Procedure, Pass, Public :: SetA => SubSetA Procedure, PAss, Public :: WriteA => SubWriteA End type TypeB Interface Module Subroutine SubSetA(this,a) Class(TypeB), Intent(InOut) :: this Real, Intent(In) :: a End Subroutine Module Subroutine SubWriteA(this) Class(TypeB), Intent(InOut) :: this End Subroutine End Interface End Module Mod_TypeB Submodule(Mod_TypeB) SubB contains Module Procedure SubSetA this%TA%a=a End Procedure Module Procedure SubWriteA write(*,*) this%TA%a End Procedure End Submodule SubB Program Main use Mod_TypeB Type(TypeB) :: tb call tb%setA(1.0) call tb%writeA() end Program Main
If both the typeB subroutines are put with the typeB module the code won't compile with complaining about a being private.
While I can see the big advantages in submodules for structuring code, what is the advantage of this?? Accessing a of typeA in the main program would require a get/set method anyway, so way skipping it in a submodule?? Is this behaviour part of the standard??
good to know.
Interestingly the code compiles without error with ifort16, ifort17 and gfortran-6.2 ........... the reason why I was uncertain about whether I missunderstood the standard.