<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國際加速解決方案。 廣告
                ## 一.成員函數的 this 指針 1. **概念** 關鍵字 `this` 是一個 **右值** (新標準為純右值)表達式,其值是對其調用成員函數的對象的地址。 2. 成員函數調用時,除了傳遞參數,程序還會傳遞一個指向自身對象的 `this` 指針。 3. 當在任何允許 `this` 關鍵詞的地方中使用非靜態數據成員時,其名字之前會自動添加隱含的 `this->` ,產生一個成員訪問表達式。 ```c++ class Square { private: int width_; int height_; public: Square(int width, int height) : width_(width), height_(height) { } int calculate() { return this->width_ * this->height_; } }; ``` 3. `this` 的類型 + 類X : `this`的類型為 `X*` + 常成員函數: `this` 的類型為 `const X*` > 由于構造函數和析構函數不能添加 `const` 限定符,因此在這些成員函數內, `this` 的類型恒為 `X*` ,即使是構造或析構一個常對象。 ## [$]二.鏈式調用的實現 1. 設置成員函數的返回類型為 **類的引用** 。 2. 返回一個 `this` 的解引用。 3. 這樣,成員函數的返回值就是自身的引用,調用完一個成員函數就可以用成員訪問運算符繼續調用另一個成員函數。 ```c++ //set_width 和 set_height 實現了鏈式調用 class Square { private: int width_; int height_; public: Square(int width, int height) : width_(width), height_(height) { } int calculate() { return this->width_ * this->height_; } Square &set_width(int width) { this->width_ = width; return *this; } Square &set_height(int height) { this->height_ = height; return *this; } }; ``` ```c++ Square s(10, 20); //鏈式調用 s.set_width(20).set_height(30); ```
                  <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>

                              哎呀哎呀视频在线观看