目前是否可以覆盖Fortran中的结构构造函数?我已经看到过像这样的提议示例(例如在Fortran 2003规范中):
module mymod
type mytype
integer :: x
! Other stuff
end type
interface mytype
module procedure init_mytype
end interface
contains
type(mytype) function init_mytype(i)
integer, intent(in) :: i
if(i > 0) then
init_mytype%x = 1
else
init_mytype%x = 2
end if
end function
end
program test
use mymod
type(mytype) :: x
x = mytype(0)
end program
Run Code Online (Sandbox Code Playgroud)
由于冗余变量名称(例如,'mytype'的错误:DERIVED属性与(1)处的PROCEDURE属性冲突),这基本上会产生一堆错误.fortran 2003示例的逐字副本会产生类似的错误.我在gfortran 4.4,ifort 10.1和11.1中尝试了这个,它们都产生了相同的错误.
我的问题:这只是2003年fortran的一个未实现的功能吗?或者我是否错误地实施了这个?
编辑:我遇到过一个错误报告和gfortran关于这个问题的公告补丁.但是,我尝试使用11月版的gcc46没有运气和类似的错误.
编辑2:上述代码似乎可以使用英特尔Fortran 12.1.0.