我正在学习 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
不存在)
我正在尝试做的事情(使用可变大小的数组和绑定(bind)过程进行类型输入)是不可能的还是我错过了有关虚拟参数定义的内容?
最佳答案
感谢@Rodrigo 的想法,我终于找到了这个错误(和补丁): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82943
要解决此问题,请下载源代码,应用提到的补丁并编译您自己的 gfortran。 (或者等到它进入存储库)
关于fortran - 长度参数化传递对象到类型绑定(bind)过程有 gfortran 提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52678258/