gpt4 book ai didi

c++ - 指针的有序关联容器

转载 作者:行者123 更新时间:2023-11-28 00:12:22 26 4
gpt4 key购买 nike

<分区>

定义指针的有序关联容器(内置的或类类型的)是否可行.) 指针未定义?

来自 c++11 标准的 5.9:

  1. If two pointers p and q of the same type point to different objects that are not members of the same object or elements of the same array or to different functions, or if only one of them is null, the results of p<q, p>q, p<=q, and p>=q are unspecified.

由于有序容器(map、set、multimap 和 multiset)使用 <默认情况下,运算符提供总顺序,它可以很好地编译以创建一组指针。然后,如果指针的关系运算符确实未指定,则可能是p<q。和 p>q两者都测试falsetrue这意味着这对于订购 set 可能不是一个好主意。 .如果不是因为我书中的示例(C++ Primer 第 5 版第 13.4 章)为类类型定义了一组指针 Folder*,我可能会接受这是一个坏主意。 ,即 set<Folder*>似乎对我的担忧没有评论。

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