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

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

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

        为什么要在 C++ 中使用嵌套类?

        Why would one use nested classes in C++?(为什么要在 C++ 中使用嵌套类?)

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

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

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

                  本文介绍了为什么要在 C++ 中使用嵌套类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有人可以指点我一些很好的资源来理解和使用嵌套类吗?我有一些像编程原则这样的材料 IBM 知识中心 - 嵌套类

                  Can someone please point me towards some nice resources for understanding and using nested classes? I have some material like Programming Principles and things like this IBM Knowledge Center - Nested Classes

                  但我仍然无法理解他们的目的.有人可以帮我吗?

                  But I'm still having trouble understanding their purpose. Could someone please help me?

                  推荐答案

                  嵌套类非常适合隐藏实现细节.

                  Nested classes are cool for hiding implementation details.

                  列表:

                  class List
                  {
                      public:
                          List(): head(nullptr), tail(nullptr) {}
                      private:
                          class Node
                          {
                                public:
                                    int   data;
                                    Node* next;
                                    Node* prev;
                          };
                      private:
                          Node*     head;
                          Node*     tail;
                  };
                  

                  在这里,我不想公开 Node,因为其他人可能决定使用该类,这会妨碍我更新我的类,因为公开的任何内容都是公共 API 的一部分,必须永远>.通过将类设为私有,我不仅隐藏了实现我还说这是我的,我可以随时更改它,因此您无法使用它.

                  Here I don't want to expose Node as other people may decide to use the class and that would hinder me from updating my class as anything exposed is part of the public API and must be maintained forever. By making the class private, I not only hide the implementation I am also saying this is mine and I may change it at any time so you can not use it.

                  看看 std::liststd::map 它们都包含隐藏的类(或者是吗?).关键是他们可能会也可能不会,但是因为实现是私有的和隐藏的,STL 的构建者能够更新代码而不影响你如何使用代码,或者在 STL 周围留下很多旧包袱,因为他们需要为了与一些决定使用隐藏在 list 中的 Node 类的傻瓜保持向后兼容性.

                  Look at std::list or std::map they all contain hidden classes (or do they?). The point is they may or may not, but because the implementation is private and hidden the builders of the STL were able to update the code without affecting how you used the code, or leaving a lot of old baggage laying around the STL because they need to maintain backwards compatibility with some fool who decided they wanted to use the Node class that was hidden inside list.

                  这篇关于为什么要在 C++ 中使用嵌套类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='94ouy'></tbody>

                  <small id='94ouy'></small><noframes id='94ouy'>

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

                          • <tfoot id='94ouy'></tfoot>