作为类型的类型成员可以作为目标吗?

发布于 2024-11-07 07:17:38 字数 386 浏览 4 评论 0原文

假设我有以下设置,

 type BarType
     integer :: i
 end type

 type FooType
    type(BarType) :: bar
 end type

我想要另一种类型

type BazType
   type(BarType), pointer :: barPtr
end type

并将 barPtr 设置为指向 foo%bar。为此,我必须声明 type(BarType), target :: bar,但出现错误。我没有进一步调查,并决定改变策略,但只是出于好奇,你知道这是允许的吗?

Suppose I have the following setup

 type BarType
     integer :: i
 end type

 type FooType
    type(BarType) :: bar
 end type

I want to have another type

type BazType
   type(BarType), pointer :: barPtr
end type

and set barPtr to point to foo%bar. To do this I would have to declare type(BarType), target :: bar, but I got an error. I didn't investigate further, and decided to change strategy, but just for curiosity, do you know if this is allowed ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随风而去 2024-11-14 07:17:38

我不是该标准的专家,但根据我的理解,派生类型组件不能具有 target 属性;如果你想将指针与这样的组件关联起来,你必须将父对象声明为target

I'm not an expert on the standard, but the way I read it, a derived-type component can not have the target attribute; if you want to associate a pointer with such a component, you have to declare the parent object as target.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文