<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準則C.136:使用多重繼承表現(xiàn)“實現(xiàn)屬性”的組合

          共 1866字,需瀏覽 4分鐘

           ·

          2020-02-10 23:25

          561656a0de120c984f06af060de97ad7.webp

          507bed8e2ca061829995e34f6162ad56.webp

          C.136: Use multiple inheritance to represent the union of implementation attributes

          C.136:使用多重繼承表現(xiàn)“實現(xiàn)屬性”的組合。?



          b9271ad71f10927001b7e26d4783bbd9.webp

          Reason(原因)

          828291b578f55d652668a4614b87c1f6.webp

          Some forms of mixins have state and often operations on that state. If the operations are virtual the use of inheritance is necessary, if not using inheritance can avoid boilerplate and forwarding.

          某些形式的混入通常包含狀態(tài)和針對狀態(tài)的操作。如果操作是虛的,使用繼承就是必要的,如果不使用繼承可以避免樣板和轉交。


          mixins就是定義一部分公共的方法或屬性,然后混入到各個組件中使用,這樣可以方便管理與修改



          b9271ad71f10927001b7e26d4783bbd9.webp

          Example(示例)

          828291b578f55d652668a4614b87c1f6.webp
          class?iostream?:?public?istream,?public?ostream?{???//?very?simplified
          ????//?...
          };

          istream?provides the interface to input operations (and some data);?ostream?provides the interface to output operations (and some data).?iostream?provides the union of the istream and ostream?interfaces and the synchronization needed to allow both on a single stream.

          istream提供輸入操作的接口(和一些數(shù)據(jù));ostream提供了輸出操作的接口(和一些數(shù)據(jù))。iostream提供istream和ostream接口的組合,同時每個單獨的流上都需要允許同步。


          b9271ad71f10927001b7e26d4783bbd9.webp

          Note(注意)

          828291b578f55d652668a4614b87c1f6.webp

          his a relatively rare use because implementation can often be organized into a single-rooted hierarchy.

          這是一種相對稀少的用法,因為實現(xiàn)通??梢越M織成一個單根繼承中。


          b9271ad71f10927001b7e26d4783bbd9.webp

          Example(示例)

          828291b578f55d652668a4614b87c1f6.webp

          Sometimes, an "implementation attribute" is more like a "mixin" that determine the behavior of an implementation and inject members to enable the implementation of the policies it requires. For example, see?std::enable_shared_from_this?or various bases from boost.intrusive (e.g.?list_base_hook?or?intrusive_ref_counter).

          有時,一個“實現(xiàn)屬性"更像一個"minxin",這個"minxin”可以決定一個實現(xiàn)的行為,也可以是使能實現(xiàn)它要求的原則的注入成員。例如,參考std::enable_shared_from_this或者來自boost.intrusive的很多基礎類(例如list_base_hook或者instrusive_ref_counter)。


          Boost.Instrusive(

          https://theboostcpplibraries.com/boost.intrusive

          )特別適合高性能編程的C++庫。



          b9271ad71f10927001b7e26d4783bbd9.webp

          Enforcement(實施建議)

          828291b578f55d652668a4614b87c1f6.webp

          ???


          b9271ad71f10927001b7e26d4783bbd9.webp

          原文鏈接

          828291b578f55d652668a4614b87c1f6.webp

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c136-use-multiple-inheritance-to-represent-the-union-of-implementation-attributes




          覺得本文有幫助?請分享給更多人。

          關注【面向對象思考】輕松學習每一天!

          面向對象開發(fā),面向對象思考!

          瀏覽 54
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  成人亚洲精品一区二区三区嫩花 | 40岁无码视频看看 | 成人毛片18女人毛片免费看麻豆 | 波多野结衣在线观看一区二区 | 日本很黄的视频免费在线观看视频 |