我已經編寫了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