<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Item 10: 讓 assignment operators(賦值運算符)返回一個 reference to \*this(引向 \*this 的引用) 作者:Scott Meyers 譯者:fatalerror99 (iTePub's Nirvana) 發布:http://blog.csdn.net/fatalerror99/ 關于 assignments(賦值)的一件有意思的事情是你可以把它們穿成一串。 ``` int x, y, z; x = y = z = 15; // chain of assignments ``` 另一件有意思的事情是 assignment(賦值)是 right-associative(右結合)的,所以,上面的賦值串可以解析成這樣: ``` x = (y = (z = 15)); ``` 這里,15 賦給 z,然后將這個 assignment(賦值)的結果(最新的 z)賦給 y,然后將這個 assignment(賦值)的結果(最新的 y)賦給 x。 這里的實現方法是讓 assignment(賦值)返回一個 reference to its left-hand argument(引向它的左側參數的引用),而且這就是當你為你的 classes(類)實現 assignment operators(賦值運算符)時應該遵守的慣例: ``` class Widget { public: ... Widget& operator=(const Widget& rhs) // return type is a reference to { // the current class ... return *this; // return the left-hand object } ... }; ``` 這個慣例適用于所有的 assignment operators(賦值運算符),而不僅僅是上面那樣的標準形式。因此: ``` class Widget { public: ... Widget& operator+=(const Widget& rhs // the convention applies to { // +=, -=, *=, etc. ... return *this; } Widget& operator=(int rhs) // it applies even if the { // operator's parameter type ... // is unconventional return *this; } ... }; ``` 這僅僅是一個慣例,代碼并不會按照這個意愿編譯。然而,這個慣例被所有的 built-in types(內建類型)和標準庫中(或者即將進入標準庫——參見 Item 54)的 types(類型)(例如,string,vector,complex,tr1::shared_ptr 等)所遵守。除非你有好的做不同事情理由,否則,不要破壞它。 Things to Remember * 讓 assignment operators(賦值運算符)返回一個 reference to \*this(引向 \*this 的引用)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看