【发布时间】:2020-08-20 02:18:12
【问题描述】:
我正在学习 Fortran,我想将一个数组和一个子例程封装在一个类型中。问题似乎出在自对象的类型定义中。
这是我想出的最小测试用例:
module testing
implicit none
type test(para)
integer, len :: para
real, dimension(para) :: weights
contains
procedure :: testing => testing_test
end type
contains
subroutine testing_test(self)
class(test(*)) :: self
end subroutine
end module
用 gfortran 编译会引发这个错误:
module_test.f08:9:23:
procedure :: testing => testing_test
1
Error: Argument ‘self’ of ‘testing_test’ with PASS(self) at (1) must be of the derived-type ‘test’
它在数组长度固定时起作用(因此type%para 不存在)
我正在尝试做的事情(类型可变大小和绑定过程的数组)是完全不可能的,还是我遗漏了一些关于虚拟参数定义的内容?
【问题讨论】:
-
这可能是一个编译器错误。您使用的是什么版本的 gfortran? pdt最近被gfortran收录了,还有一些bug。
-
gfortran --version的结果:GNU Fortran (GCC) 8.1.1 20180712 (Red Hat 8.1.1-5)
标签: fortran gfortran type-definition