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

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

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

        何时使用 C++ 私有继承而不是组合?

        时间:2023-08-02

            <bdo id='j4F2R'></bdo><ul id='j4F2R'></ul>

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

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

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

                1. <legend id='j4F2R'><style id='j4F2R'><dir id='j4F2R'><q id='j4F2R'></q></dir></style></legend>
                    <tbody id='j4F2R'></tbody>
                2. 本文介绍了何时使用 C++ 私有继承而不是组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  你能举一个具体的例子,什么时候最好使用私有继承而不是组合?就个人而言,我将使用组合而不是私有继承,但在某些情况下,使用私有继承可能是特定问题的最佳解决方案.阅读 C++ faq,为您提供了一个使用示例私有继承,但我似乎更容易使用组合+策略模式,甚至比私有继承更容易使用公共继承.

                  Can you give me a concrete example when is preferable to use private inheritance over composition? Personally, I will use composition over private inheritance, but there might be the case that using private inheritance is the best solution for a particular problem. Reading the C++ faq, gives you an example on using private inheritance, but I seems easier to use composition + strategy pattern or even public inheritance than private inheritance.

                  推荐答案

                  private 继承通常用于表示implemented-in-terms-of".我看到的主要用途是使用私有多重继承的 mixin 来构建具有来自各种 mixin 父项的适当功能的子对象.这也可以通过组合来完成(我稍微喜欢),但是继承方法确实允许您使用 using 公开公开一些父方法,并且在使用 mixin 方法时允许使用更方便的符号.

                  private inheritance is typically used to represent "implemented-in-terms-of". The main use I have seen is for mixins using private multiple inheritance to build up a child object with the proper functionality from the various mixin parents. This can also be done with composition (which I slightly prefer) but the inheritance method DOES allow you to use using to expose some parent methods publicly, and allows for a slightly more convenient notation when using the mixin methods.

                  这篇关于何时使用 C++ 私有继承而不是组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么虚拟基类必须由最派生的类构造? 下一篇:切片在 C++ 中是什么意思?

                  相关文章

                  最新文章

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

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

                3. <tfoot id='BE0et'></tfoot>
                4. <legend id='BE0et'><style id='BE0et'><dir id='BE0et'><q id='BE0et'></q></dir></style></legend>
                    • <bdo id='BE0et'></bdo><ul id='BE0et'></ul>