Fortran 重写不同模块中的私有函数
如果模块Fortran 重写不同模块中的私有函数,fortran,polymorphism,Fortran,Polymorphism,如果模块foo中私有的类型绑定过程被第二个模块bar中的类型覆盖(或试图覆盖),如何解决此问题?标准中有什么规定吗?考虑到下面的示例代码(取决于编译器)会打印FOO(英特尔fortan 19.1.1)或BAR(gfortran 7.5,可能更新版本会给出不同的结果?),我想知道哪个是正确的 module foo type :: foo_t contains procedure, private :: foobar procedure :: exec end type foo_t
foo
中私有的类型绑定过程被第二个模块bar
中的类型覆盖(或试图覆盖),如何解决此问题?标准中有什么规定吗?考虑到下面的示例代码(取决于编译器)会打印FOO(英特尔fortan 19.1.1)或BAR(gfortran 7.5,可能更新版本会给出不同的结果?),我想知道哪个是正确的
module foo
type :: foo_t
contains
procedure, private :: foobar
procedure :: exec
end type foo_t
contains
subroutine exec(obj)
class(foo_t) :: obj
call obj%foobar()
end subroutine exec
subroutine foobar(this)
class(foo_t) :: this
print *, "FOO"
end subroutine foobar
end module foo
module bar
use foo
type, extends(foo_t) :: bar_t
contains
procedure :: foobar => impl
end type bar_t
contains
subroutine impl(this)
class(bar_t) :: this
print *, "BAR"
end subroutine impl
end module bar
program test
use foo
use bar
class(foo_t), allocatable :: inst
allocate( bar_t :: inst)
call inst%exec()
end program test
此外,是否可以在不同的模块中使用私有延迟方法扩展抽象类型,就像示例中的情况一样,如果
foobar
被延迟(仅使用前面提到的gfortran编译器编译,然后生成预期结果,但问题是这是否也是正确的行为)?正确的结果是FOO
这是gfortran()中的一个已知错误
在另一个模块中无法访问专用绑定。由于无法在模块栏中访问专用绑定,因此不会覆盖它(F2018 7.5.7.3p1)。bar\u t中的绑定定义与foo\u t中的绑定无关
(具有专用延迟绑定的抽象类型在定义它的模块外部不可用。有关详细信息,请参阅解释F08/0052。)