• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Zero Lee的專欄

            構造函數,拷貝構造,拷貝賦值

            Example1:
             1 class A {
             2 public:
             3     A() {
             4         std::cout << "A.ctor()" << std::endl;
             5     }
             6     A(const A& other) {
             7         std::cout << "A.copyctor()" << std::endl;
             8     }
             9     A& operator =(const A& other) {
            10         std::cout << "A.op =() " << std::endl;
            11     }
            12 };
            13 
            14 class AA : public A
            15 {
            16 public:
            17     AA() {
            18         std::cout << "AA.ctor()" << std::endl;
            19     }
            20 };
            21 
            22 int main()
            23 {
            24     AA aa;  // A.ctor => AA.ctor
            25     AA bb(aa);  // A.copyctor
            26     aa = bb;    // A.op =
            27     return 0;
            28 }
            29 
            1. 編譯器會默認調用基類的構造函數。
            2. 繼承類的拷貝構造函數/拷貝賦值運算符函數沒有定義,編譯器會默認調用基類相應的函數。

            Example2:
             1 class A {
             2 public:
             3     A() {
             4         std::cout << "A.ctor()" << std::endl;
             5     }
             6     A(const A& other) {
             7         std::cout << "A.copyctor()" << std::endl;
             8     }
             9     A& operator =(const A& other) {
            10         std::cout << "A.op =() " << std::endl;
            11     }
            12 };
            13 
            14 class AA : public A
            15 {
            16 public:
            17     AA() {
            18         std::cout << "AA.ctor()" << std::endl;
            19     }
            20     AA(const AA& other)
            21     : A(other) {
            22         std::cout << "AA.copyctor() " << std::endl;
            23     }
            24     AA& operator =(const AA& other) {
            25         std::cout << "AA.op =()" << std::endl;
            26     }
            27 };
            28 
            29 int main()
            30 {
            31     AA aa;  // A.ctor => AA.ctor
            32     AA bb(aa);  // A.copyctor => AA.copyctor
            33     aa = bb;    // AA.op =
            34                                 
            35     return 0;
            36 }
            1. 拷貝構造函數會默認調用基類的構造函數,而不是對應的拷貝構造函數,除非在自己手動調用。
            2. 自定義的拷貝賦值運算符函數,也不會調用基類的相應函數。


            posted on 2010-12-03 15:21 Zero Lee 閱讀(264) 評論(0)  編輯 收藏 引用 所屬分類: CC++ Programming

            国产激情久久久久久熟女老人| 97香蕉久久夜色精品国产 | 亚洲欧洲日产国码无码久久99| 香蕉99久久国产综合精品宅男自 | 精品国产青草久久久久福利| 久久r热这里有精品视频| 久久久久黑人强伦姧人妻| 成人久久免费网站| 伊人色综合久久天天| 久久亚洲精品国产精品婷婷 | 99久久综合国产精品免费| 久久精品亚洲一区二区三区浴池| 9999国产精品欧美久久久久久| 欧美成a人片免费看久久| 国产精品激情综合久久| 无码人妻久久一区二区三区免费丨| 精品乱码久久久久久久| 久久无码中文字幕东京热| 97久久国产亚洲精品超碰热| 久久99热这里只有精品国产| 亚洲国产天堂久久综合网站| 中文精品久久久久人妻不卡| 久久青草国产精品一区| 久久精品国产69国产精品亚洲| 中文字幕无码久久精品青草 | 99久久国产综合精品网成人影院| 久久这里只精品99re66| 久久精品99无色码中文字幕| 精品人妻久久久久久888| 久久婷婷色综合一区二区| 久久久久无码专区亚洲av| 欧美久久综合性欧美| 99久久免费国产特黄| 日韩精品久久无码人妻中文字幕 | 久久黄色视频| 国产午夜电影久久| 久久99久久成人免费播放| 人妻丰满?V无码久久不卡| 久久久久国色AV免费看图片| 精品久久人人妻人人做精品| 精品国产乱码久久久久久浪潮|