• <bdo id='9rkaU'></bdo><ul id='9rkaU'></ul>

      <small id='9rkaU'></small><noframes id='9rkaU'>

      <legend id='9rkaU'><style id='9rkaU'><dir id='9rkaU'><q id='9rkaU'></q></dir></style></legend>
      <i id='9rkaU'><tr id='9rkaU'><dt id='9rkaU'><q id='9rkaU'><span id='9rkaU'><b id='9rkaU'><form id='9rkaU'><ins id='9rkaU'></ins><ul id='9rkaU'></ul><sub id='9rkaU'></sub></form><legend id='9rkaU'></legend><bdo id='9rkaU'><pre id='9rkaU'><center id='9rkaU'></center></pre></bdo></b><th id='9rkaU'></th></span></q></dt></tr></i><div id='9rkaU'><tfoot id='9rkaU'></tfoot><dl id='9rkaU'><fieldset id='9rkaU'></fieldset></dl></div>
      <tfoot id='9rkaU'></tfoot>

    1. 我们可以为 STL 映射中的键使用用户定义的类吗?

      时间:2024-05-11
        <tbody id='oh1wz'></tbody>

      1. <small id='oh1wz'></small><noframes id='oh1wz'>

        <tfoot id='oh1wz'></tfoot>
          <bdo id='oh1wz'></bdo><ul id='oh1wz'></ul>
          • <i id='oh1wz'><tr id='oh1wz'><dt id='oh1wz'><q id='oh1wz'><span id='oh1wz'><b id='oh1wz'><form id='oh1wz'><ins id='oh1wz'></ins><ul id='oh1wz'></ul><sub id='oh1wz'></sub></form><legend id='oh1wz'></legend><bdo id='oh1wz'><pre id='oh1wz'><center id='oh1wz'></center></pre></bdo></b><th id='oh1wz'></th></span></q></dt></tr></i><div id='oh1wz'><tfoot id='oh1wz'></tfoot><dl id='oh1wz'><fieldset id='oh1wz'></fieldset></dl></div>

            • <legend id='oh1wz'><style id='oh1wz'><dir id='oh1wz'><q id='oh1wz'></q></dir></style></legend>
                本文介绍了我们可以为 STL 映射中的键使用用户定义的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要地图中的一个键,但是,我发现它应该是多个数据.我可以将这些数据放在一个用户定义的类中,并将整个类作为映射中的键吗?

                I need a key in the map, however, I found it should be multiple data. Can I put these data in one user defined class and put the whole class as a key in the map?

                会影响时间效率吗?

                此处还应考虑哪些其他问题?

                What other concerns should be applied here?

                推荐答案

                任何类型都可以作为key使用

                Any type can be used as a key as long as it is

                • 可复制
                • 可分配
                • 具有可比性,因为地图是按键排序的

                如果你的类只是一个简单的结构,那么它已经是可复制和可分配的.要使类具有可比较性,您必须实现 operator<,或者使用自定义比较函数创建映射以供替代.

                If your class is just a simple structure, then it's already copyable and assignable. For a class to be comparable, you must either implement operator<, or create the map with a custom comparison function to use instead.

                对时间效率的唯一影响来自较大的对象需要更长的时间来复制和比较.如果对象需要那么大,那么您无能为力,所以不用担心.

                The only impact on time efficiency comes from larger objects taking longer to copy and compare. If the objects need to be that size, then there's nothing you can do about that, so don't worry about it.

                这篇关于我们可以为 STL 映射中的键使用用户定义的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:是 std::pair<int, std::string>订购明确? 下一篇:在 std::vector<bool> 上调用 data() 会发生什么?

                相关文章

                <small id='PwVJD'></small><noframes id='PwVJD'>

                <legend id='PwVJD'><style id='PwVJD'><dir id='PwVJD'><q id='PwVJD'></q></dir></style></legend>

              1. <tfoot id='PwVJD'></tfoot>
                  <bdo id='PwVJD'></bdo><ul id='PwVJD'></ul>

                  <i id='PwVJD'><tr id='PwVJD'><dt id='PwVJD'><q id='PwVJD'><span id='PwVJD'><b id='PwVJD'><form id='PwVJD'><ins id='PwVJD'></ins><ul id='PwVJD'></ul><sub id='PwVJD'></sub></form><legend id='PwVJD'></legend><bdo id='PwVJD'><pre id='PwVJD'><center id='PwVJD'></center></pre></bdo></b><th id='PwVJD'></th></span></q></dt></tr></i><div id='PwVJD'><tfoot id='PwVJD'></tfoot><dl id='PwVJD'><fieldset id='PwVJD'></fieldset></dl></div>