<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)則R.33: 表達(dá)函數(shù)會(huì)重置widget時(shí),使用unique_ptr...

          425e98af5675968faf3c6188383bbbdf.webp

          R.33: Take a?unique_ptr&?parameter to express that a function reseats the widget

          R.33:? 表達(dá)函數(shù)會(huì)重置widget時(shí),使用unique_ptr&作參數(shù)。


          Reason(原因)

          Using?unique_ptr?in this way both documents and enforces the function call's reseating semantics.

          以這種方式使用unique_ptr可以從文檔和實(shí)現(xiàn)兩個(gè)方面強(qiáng)制函數(shù)調(diào)用的重置語義。


          Note(注意)

          "reseat" means "making a pointer or a smart pointer refer to a different object."

          “重置”的意思是使指針或者智能指針參照另外一個(gè)對(duì)象。


          Example(示例)

          void reseat(unique_ptr&); // "will" or "might" reseat pointer

          Example, bad(反面示例)
          void thinko(const unique_ptr&); // usually not what you want

          Enforcement(實(shí)施建議)
          • (Simple) Warn if a function takes a?Unique_pointer?parameter by lvalue reference and does not either assign to it or call?reset()?on it on at least one code path. Suggest taking a?T*?or?T&?instead.

          • (簡(jiǎn)單)如果一個(gè)函數(shù)以左值引用方式使用了Unique_pointer類型參數(shù),卻沒有至少一個(gè)代碼路徑上對(duì)它賦值或者調(diào)用reset方法,提出警告。建議改用T*或者T&?。

          • (Simple) ((Foundation)) Warn if a function takes a?Unique_pointer?parameter by reference to?const. Suggest taking a?const T*?or?const T&?instead.

          • (簡(jiǎn)單)((基礎(chǔ)))如果一個(gè)函數(shù)以常量引用形式使用了Unique_pointer參數(shù),提出警告。建議改用const T* 或 const T&。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r32-take-a-unique_ptrwidget-parameter-to-express-that-a-function-assumes-ownership-of-a-widget




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

          關(guān)注微信公眾號(hào)【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

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



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

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          <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>
                  99在线观看免费视频 | 蜜桃精品视频在线观看 | 操在线综合 | 人妻.少妇.欧美.亚洲.日韩 | 乌克兰毛片 |