gpt4 book ai didi

scope - 为什么类型不可访问?

转载 作者:行者123 更新时间:2023-11-30 16:12:38 26 4
gpt4 key购买 nike

我正在尝试从 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

我尝试将类型明确公开,但这没有帮助。我打算使用 somefunction 的 C 版本,这就是为什么我把它放在接口(interface)部分。

为什么类型不可访问?

最佳答案

在函数定义中添加导入可以解决此问题。由于许多人认为语言设计中存在错误,定义不会在接口(interface)内部继承。 “导入”会覆盖它以实现合理的行为。

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

关于scope - 为什么类型不可访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58292010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com