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

      1. <legend id='3jEDl'><style id='3jEDl'><dir id='3jEDl'><q id='3jEDl'></q></dir></style></legend>
        • <bdo id='3jEDl'></bdo><ul id='3jEDl'></ul>

        <small id='3jEDl'></small><noframes id='3jEDl'>

        <tfoot id='3jEDl'></tfoot>

        为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?

        Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)
              <i id='OaMbO'><tr id='OaMbO'><dt id='OaMbO'><q id='OaMbO'><span id='OaMbO'><b id='OaMbO'><form id='OaMbO'><ins id='OaMbO'></ins><ul id='OaMbO'></ul><sub id='OaMbO'></sub></form><legend id='OaMbO'></legend><bdo id='OaMbO'><pre id='OaMbO'><center id='OaMbO'></center></pre></bdo></b><th id='OaMbO'></th></span></q></dt></tr></i><div id='OaMbO'><tfoot id='OaMbO'></tfoot><dl id='OaMbO'><fieldset id='OaMbO'></fieldset></dl></div>

              • <tfoot id='OaMbO'></tfoot>

              • <legend id='OaMbO'><style id='OaMbO'><dir id='OaMbO'><q id='OaMbO'></q></dir></style></legend>
                  <bdo id='OaMbO'></bdo><ul id='OaMbO'></ul>

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

                    <tbody id='OaMbO'></tbody>

                • 本文介绍了为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  突然在这篇文章(问题 2") 我看到一个声明,即 C++ 标准禁止使用 STL 容器来存储类的元素,如果该类具有重载的 operator&().

                  Suddenly in this article ("problem 2") I see a statement that C++ Standard prohibits using STL containers for storing elemants of class if that class has an overloaded operator&().

                  重载 operator&() 确实有问题,但看起来可以通过一组看起来很脏的演员表在 boost::addressof() 中使用,被认为是可移植和符合标准的.

                  Having overloaded operator&() can indeed be problematic, but looks like a default "address-of" operator can be used easily through a set of dirty-looking casts that are used in boost::addressof() and are believed to be portable and standard-compilant.

                  为什么在存在 boost::addressof() 解决方法的情况下禁止存储在 STL 容器中的类使用重载的 operator&()?

                  Why is having an overloaded operator&() prohibited for classes stored in STL containers while the boost::addressof() workaround exists?

                  推荐答案

                  在没有查看链接的情况下,我认为 boost::addressof() 中的技巧是在要求不为要保存在 std lib 容器中的对象重载一元前缀 &.

                  Without having looked at the links, I suppose the tricks in boost::addressof() were invented well after the requirement to not to overload unary prefix & for objects to be held in containers of the std lib.

                  我依稀记得 Pete Becker(当时为 Dinkumware 的标准库实现工作)曾经说过,每个重载 address-of 运算符并希望他们的标准库实现仍然有效的人都应该受到惩罚,必须实现一个标准库做这个.

                  I vaguely remember Pete Becker (then working for Dinkumware on their standard library implementation) once stating that everyone who overloads the address-of operator and expects their standard library implementation still to work should be punished by having to implement a standard library which does this.

                  这篇关于为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                    <tbody id='sfGXj'></tbody>
                  • <bdo id='sfGXj'></bdo><ul id='sfGXj'></ul>
                    <legend id='sfGXj'><style id='sfGXj'><dir id='sfGXj'><q id='sfGXj'></q></dir></style></legend>
                      <tfoot id='sfGXj'></tfoot>

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

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