<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++核心準則R.32: 通過?unique_ptr類型參數表示函數試圖獲...

          共 1251字,需瀏覽 3分鐘

           ·

          2020-04-09 23:24

          2240ebde5b849d71ccfd76344cba86e1.webp

          R.32: Take a?unique_ptr?parameter to express that a function assumes ownership of a?widget

          R.32: 通過unique_ptr類型參數表示函數試圖獲取widget的所有權


          Reason(原因)

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

          以這種方式使用unique_ptr可以從文檔和實現兩個方面強制進行所有權的移交。


          Example(示例)

          void sink(unique_ptr); // takes ownership of the widget

          void uses(widget*); // just uses the widget
          Example, bad(反面示例)
          void thinko(const unique_ptr&); // usually not what you want
          Enforcement(實施建議)
          • (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.

          • (簡單)如果一個函數通過左值引用方式使用了Unique_pointer參數,卻沒有對它賦值,或者在至少一條代碼路徑上調用了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.

          • (簡單)((基本))?如果一個函數以常量引用方式使用Unique_pointer參數,建議使用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




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

          關注微信公眾號【面向對象思考】輕松學習每一天!

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




          瀏覽 98
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

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

          手機掃一掃分享

          分享
          舉報
          <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>
                  日本做爰乱高潮A片分手的决心 | 91精品国产日韩91久久久久久 | 最新中文字幕免费MV第一季歌词 | 成人女a在线免费 | 亚洲每日在线 |