<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++核心準(zhǔn)則C.151:使用make_shared構(gòu)建shared_ptr管理的對(duì)象

          1b1c3a5e70edde52b822861bf9d807ae.webp

          C.151: Use?make_shared()?to construct objects owned by shared_ptrs

          C.151:使用make_shared構(gòu)建shared_ptr管理的對(duì)象



          Reason(原因)

          make_shared?gives a more concise statement of the construction. It also gives an opportunity to eliminate a separate allocation for the reference counts, by placing the?shared_ptr's use counts next to its object.

          make_shared為構(gòu)造動(dòng)作提供了更加簡(jiǎn)明的表達(dá)。由于它將shared_ptr的計(jì)數(shù)置于對(duì)象之后,使用它還可以提供減少另外一次的增加計(jì)數(shù)的機(jī)會(huì)。


          Example(示例)

          void test() {
          // OK: but repetitive; and separate allocations for the Bar and shared_ptr's use count
          shared_ptr p {new Bar{7}};

          auto q = make_shared(7); // Better: no repetition of Bar; one object
          }

          Enforcement(實(shí)施建議)
          • Flag the repetitive usage of template specialization list

          • 提示重復(fù)使用模板特化參數(shù)列表的情況

          • Flag variables declared to be?shared_ptr

          • 提示使用shared_ptr直接定義變量的情況。


          原文鏈接:

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c151-use-make_shared-to-construct-objects-owned-by-shared_ptrs




          覺(jué)得本文有幫助?請(qǐng)分享給更多人。

          關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>

          瀏覽 37
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          C++核心準(zhǔn)則R.22: 使用make_shared()構(gòu)建共享shared_ptr
          <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>
                  国产足交网站 | 亚洲精品色婷婷 | 一级欧美视频 | 操逼达人| 国产精品色在线 |