sách gpt4 ai đã đi

fortran - 在 PURE 过程 Fortran 中调用类型绑定(bind)过程

In lại 作者:行者123 更新时间:2023-12-02 14:34:27 29 4
mua khóa gpt4 Nike

如果我声明了类似的类型

 type test(NSIZE)
integer, len :: NSIZE
real :: dummy(NSIZE)
contains
procedure, pass(this) :: proc

end test
type(test(NSIZE=10)) :: test_type

của tôiproc子例程是纯粹的。我的过程返回一个值并且没有任何副作用。

 pure subroutine proc(this, n) 
implicit none
class(test(NSIZE=*)), intent(inout) :: this
integer, intent(inout) :: n
n = n +1
end subroutine proc

现在在另一个也声明为 PURE 的子例程中我调用 proc

  pure subroutine test2 

integer :: n

call test_type% proc(n)
end subroutine test2

我在调用 test% proc(n) 时收到错误,内容如下:

错误 #7140:此全局使用关联对象出现在 PURE 过程的“定义”上下文中或 PURE 过程中包含的内部过程中。

一个独立的示例

module mod1
implicit none

type test (size)
integer, len :: size
real :: dum(size)
contains
procedure, pass(this) :: dum_proc
end type

type(test(size=10)) :: test1

contains

pure subroutine dum_proc(this, n )
implicit none
class(test(size=*)), intent(inout) :: this
integer, intent(out) :: n
n =n +2
end subroutine dum_proc
end module mod1


program SUPPORT


implicit none
integer :: n

n = 0

call caller(n)


contains
pure subroutine caller( nk )
use mod1, only : test1
implicit none

integer, intent(inout) :: nk

call test1% dum_proc(nk)

end subroutine

end program SUPPORT`

1 Câu trả lời

您的问题来自通话

call test1% dum_proc(nk)

因为纯子例程callerTRONGtest1已被使用关联,所以不允许是与具有intent(inout ) 属性。在对类型绑定(bind)过程 test1 的调用中, 与传递的对象虚拟参数 cái này 关联(具有该意图)。

intent(inout) 虚拟参数关联算作变量定义上下文,这就是错误消息中“'defining' context”的含义。实际上,不必更改参数即可使其处于定义上下文中。

如果您将 test1 BẰNG intent(inout) 虚拟参数,则此限制不适用。关联 test1 chủ nhà 与使用关联具有相同的限制。

关于fortran - 在 PURE 过程 Fortran 中调用类型绑定(bind)过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55041983/

29 4 0
Bài viết được đề xuất: asp.net - 为什么皮肤文件中的控件需要 runat ="server"?
Bài viết được đề xuất: javascript - 函数被调用多次
Bài viết được đề xuất: javascript - 返回长度为 5 的空白数组
Bài viết được đề xuất: haskell - 如何重置 Haskell 包缓存
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com