次のコードでは、プライベート変数 (名前) を持つ抽象型と、すべての派生型によって定義されるこの変数へのアクセス関数がモジュールで定義されています。
module baseTypeModule
type, abstract :: baseType
private
character(len=maxLengthCompLabel) :: Name = "" ! Component name
contains
procedure, non_overridable :: getName ! Access functio to Name (read only)
end type baseType
contains
character(len=100) function getName(this)
implicit none
class(baseType), intent(in) :: this
getName = this % Name
end function getName
end module baseTypeModule
各派生型には他にも多くの変数と関数があるため、各派生型を別のモジュールで定義したいと思います。
Fortran で、baseType の派生型のみが変数 Name を変更できるようにすることをコンパイラーに伝える方法はありますか?