다른 텍스트 파일을 읽는 포트란 코드를 작성했습니다.형식 오버로딩을 위해 인터페이스 블록을 사용하는 방법
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