【发布时间】:2017-03-09 20:10:25
【问题描述】:
我编写了一个 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 函数来解决这个问题,但是我必须对每个继承类都这样做,我自然想避免这种情况。有什么建议吗?
【问题讨论】:
标签: inheritance interface fortran overloading fortran2003