2012-01-05 89 views
3

我试图从fortran函数返回一个类型。这是代码。为什么不能访问该类型?

module somemodule 
implicit none 
! define a simple type 
type sometype 
    integer :: someint 
end type sometype 
! define an interface 
interface 
    ! define a function that returns the previously defined type 
    type(sometype) function somefunction() 
    end function somefunction 
end interface 
contains 
end module somemodule 

在gfortran(4.4 & 4.5)我收到以下错误:

Error: The type for function 'somefunction' at (1) is not accessible

我编译的文件:

gfortran -c ./test.F90 

我试图让类型明确公开,但该没有帮助。我打算使用某种功能的c版本,这就是为什么我把它放在界面部分。

为什么类型不可访问?

回答

5

加入导入函数定义里面定义了这个。由于许多人认为语言设计中存在错误,因此定义不会在接口中继承。 “导入”优先于此来实现明智的行为。

interface 
    ! define a function that returns the previously defined type 
    type(sometype) function somefunction() 
    import 
    end function somefunction 
end interface 
3

问题为何无法访问的答案是标准委员会就是这样设计的。该接口与封闭模块有一个单独的作用域,因此您必须从中明确导入名称。显然(?)你不能在use模块内部,所以需要import声明。

相关问题