私は異なるテキストファイルを読むためにFortranコードを書いています。各テキストファイルには、一般的な操作を定義する抽象型から継承読み取り手順を定義して、独自の型を持つ:タイプオーバーロードのためのインターフェイスブロックの使用方法
module FileImporter_class
implicit none
private
type, abstract, public :: FileImporter
.
.
contains
procedure, public :: ProcessFile
.
.
end type FileImporter
contains
.
.
subroutine ProcessFile(self,FileName)
implicit none
! Declaring Part
class(FileImporter) :: self
character(len=*) :: FileName
! Executing Part
call self%SetFileName(FileName)
call self%LoadFileInMemory
call self%ParseFile
end subroutine ProcessFile
end module FileImporter_class
ここでは、継承クラスです:
module optParser_class
use FileImporter_class
implicit none
type, public, extends(FileImporter) :: optParser
.
.
contains
procedure, public :: ParseFile
end type optParser
interface optParser
procedure ProcessFile
end interface
contains
.
.
end module optParser_class
私の質問は、インターフェースブロックについてです。単純に型を呼び出すことによって、ProcessFile
プロシージャを呼び出すので、call optParser('inputfile.txt')
です。表示されているこのバリアントは、コンパイルエラー(ProcessFile関数またはサブルーチンではありません)を示します。私はこれをoptParser_class
モジュールにProcessFile
という関数を入れて解決することができましたが、私が当然避けたいすべての継承クラスに対してこれを行う必要がありました。どのようにこれを行うための任意の提案?
ありがとうございます。私はまだFortranのOOPを初めて使っているので、適用可能なものと許可されていないものとは何か分かりません。 – THo