• <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>

            千里之行,始于足下

            《effetive c++》學習筆記 Introduction

             

            Introduction
            1)declarations and definition
                     

            extern int x;                          // object declaration
            int x;                                 // object definition


            2)默認構造函數,要么沒有參數,要么制定參數的初始值,否則定義類的數組的時候會出錯。

            class A ;
            A arrayA[
            10];                            // 10 constructors called

            class B ;

            B arrayB[
            10];                            // 10 constructors called,
                                                     
            // each with an arg of 0
            class C ;
            C arrayC[
            10];                            // error!


            對無法直接聲明為數組對象的類,則需要使用指針數組。

            *ptrArray[10];                          // no constructors called

            ptrArray[
            0= new C(22);                  // allocate and construct
                                                      
            // 1 C object
            ptrArray[1= new C(4);                   // ditto


            3)copy constructor 主要用于值傳遞的類
               

            class String ;
            String s1;                                 
            // call default constructor
            String s2(s1);                             // call copy constructor
            String s3 = s2;                            // call copy constructor


            4)initialization 與 assignment

            string s1;                                // initialization
            string s2("Hello");                       // initialization
            string s3 = s2;                           // initialization
            s1 = s3;                                  // assignment


            前者是在構造函數中,后者是利用賦值操作符”=”,實際就是調用的函數不同。前者注重數據的合法性,而后者注重數據內存的管理。

            // a possible String constructor
            String::String(const char *value)
            {
              
            if (value) {                            // if value ptr isn't null
                data = new char[strlen(value) + 1];
                strcpy(data,value);
              }

              
            else {                                  // handle null value ptr3
              
                data 
            = new char[1];
                
            *data = '\0';                         // add trailing null char
              }

            }

            // a possible String assignment operator
            String& String::operator=(const String& rhs)
            {
              
            if (this == &rhs)
                
            return *this;                          // see Item 17

              delete [] data;                          
            // delete old memory
              data =                                   // allocate new memory
                new char[strlen(rhs.data) + 1];
              strcpy(data, rhs.data);

              
            return *this;                            // see Item 15
            }


             
            5)幾種表達方式
            1,const_cast is designed to cast away the constness of objects and pointers, a topic I examine in Item 21.
            2,dynamic_cast is used to perform "safe downcasting," a subject we'll explore in Item 39.
            3,reinterpret_cast is engineered for casts that yield implementation-dependent results, e.g., casting between function pointer types. (You're not likely to need reinterpret_cast very often. I don't use it at all in this book.)
            4,static_cast is sort of the catch-all cast. It's what you use when none of the other casts is appropriate. It's the closest in meaning to the conventional C-style casts.

             

            posted on 2007-12-06 16:58 rednight 閱讀(228) 評論(0)  編輯 收藏 引用

            新狼窝色AV性久久久久久| 狠狠色婷婷久久一区二区| 久久久久四虎国产精品| 国产精品狼人久久久久影院| 99久久精品免费观看国产| 天天做夜夜做久久做狠狠| 亚洲AV无码久久寂寞少妇| 94久久国产乱子伦精品免费| 伊人色综合九久久天天蜜桃| 久久国产精品无码一区二区三区 | 狠狠色丁香久久婷婷综合五月 | 国产精品久久久久…| 亚洲另类欧美综合久久图片区| 久久久久AV综合网成人| 久久国产成人午夜aⅴ影院| 久久精品无码专区免费青青| 久久久久一级精品亚洲国产成人综合AV区 | 性做久久久久久久久老女人| 国产精品久久影院| 久久久久久国产精品无码超碰| 久久午夜无码鲁丝片午夜精品| 精品久久久久久| 国产精品无码久久久久久| 国产A三级久久精品| 久久人人爽人人爽人人片AV东京热| 潮喷大喷水系列无码久久精品| 久久久久亚洲av成人网人人软件| 久久激情亚洲精品无码?V| 91精品国产高清久久久久久国产嫩草 | 久久中文精品无码中文字幕| 久久91精品久久91综合| 久久久噜噜噜久久熟女AA片| 伊人久久五月天| 四虎亚洲国产成人久久精品| 久久久久亚洲av成人无码电影| 久久精品国产福利国产秒| 精品久久久久中文字幕日本| 国产成人精品免费久久久久| 精品久久久久久成人AV| 久久无码人妻一区二区三区午夜| 久久人人爽人人爽人人片AV不|