<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國際加速解決方案。 廣告
                有了Deck對象之后,把所有從屬于Deck的函數放入其結構定義中也是情理之中的事了。看一下到目前為止我們定義的函數,很明顯12.7節的printDeck函數可以作為候選加進來。下面將printDeck重寫為成員函數: ~~~ void Deck::print () const { for (int i = 0; i < cards.length(); i++) { cards[i].print (); } } ~~~ 通常,引用當前對象不需要使用點記號。 其他幾個函數,至于是否應將它們變為Card或Deck的成員函數,還是作為以Card或Deck變量為參數的非成員函數,并非顯而易見的。比如上一章以一個Card變量和一個Deck變量為參數的find函數,將它變為Card或Deck類型的成員函數都是合理的。作為練習,請重寫find函數,其參數為Card類型,使之成為Deck的成員函數。 將find改寫為Card的成員函數需要一些小技巧,這是我寫的版本: ~~~ int Card::find (const Deck& deck) const { for (int i = 0; i < deck.cards.length(); i++) { if (equals (deck.cards[i], *this)) return i; } return -1; } ~~~ 一個技巧是,必須使用this關鍵字來引用調用find函數的對象;再就是在C++中定義相互引用的結構也需要一點技巧,因為編譯器正在讀取第一個結構定義時還不知道第二個結構的定義。 一種解決方案是,在Card定義之前先聲明Deck,以后再給出Deck的定義。 ~~~ // 聲明Deck結構,這里不定義declare that Deck is a structure, without defining it struct Deck; // 這樣我們就可以在Card的定義中引用Deck struct Card { int suit, rank; Card (); Card (int s, int r); void print () const; bool isGreater (const Card& c2) const; int find (const Deck& deck) const; }; // 后面給出Deck的定義 struct Deck { apvector<Card> cards; Deck (); Deck (int n); void print () const; int find (const Card& card) const; }; ~~~
                  <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>

                              哎呀哎呀视频在线观看