作为类型的类型成员可以作为目标吗?
假设我有以下设置,
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是该标准的专家,但根据我的理解,派生类型组件不能具有
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 astarget
.