清单的清单?

发布于 2024-12-14 20:42:39 字数 286 浏览 2 评论 0原文

尝试创建涉及列表的自定义数据类型,并且接受大多数通用类型似乎没问题 我不知道如何制作列表列表,但似乎......

在我的主要程序中,我希望摆脱这样的事情:

type INFO is record
   Neighbors:List(ITEM => Unbounded_String);
   Name:Unbounded_String;
end record;
package Graph is new List(ITEM => INFO);

为什么这不起作用?

Trying to make a custom data type involving lists, and it seems to be fine accepting most generic types
I don't know how to make a list of lists though, it seems...

In my main procedure I was hoping to get away with something like this:

type INFO is record
   Neighbors:List(ITEM => Unbounded_String);
   Name:Unbounded_String;
end record;
package Graph is new List(ITEM => INFO);

Why doesn't this work?

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

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

发布评论

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

评论(1

双手揣兜 2024-12-21 20:42:39

那么,对于您的 Neighbors 字段,您必须指定一个类型。那里的错误语法让人想起通用实例化。

更多类似的内容(警告,未编译):

package List_Of_Strings is new List(Item => Unbounded_String);

type INFO is record
   Neighbors:List_Of_Strings.List_Type;
   Name:Unbounded_String;
end record;
package Graph is new List(ITEM => INFO);

然后 Graph.List_Type 将是您的信息记录列表。

不过要小心!更新列表项时,您必须清楚地了解按值传递与按引用传递语义。

Well, for your Neighbors field you have to specify a type. The incorrect syntax that's there is reminiscent of a generic instantiation.

Something more along the lines of this (warning, not compiled):

package List_Of_Strings is new List(Item => Unbounded_String);

type INFO is record
   Neighbors:List_Of_Strings.List_Type;
   Name:Unbounded_String;
end record;
package Graph is new List(ITEM => INFO);

Then Graph.List_Type will be your list of Info records.

Caution, though! You have to keep a clear understanding of pass-by-value vs pass-by-reference semantics when updating list items.

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