• <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)默認構(gòu)造函數(shù),要么沒有參數(shù),要么制定參數(shù)的初始值,否則定義類的數(shù)組的時候會出錯。

            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!


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

            *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


            前者是在構(gòu)造函數(shù)中,后者是利用賦值操作符”=”,實際就是調(diào)用的函數(shù)不同。前者注重數(shù)據(jù)的合法性,而后者注重數(shù)據(jù)內(nèi)存的管理。

            // 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 閱讀(223) 評論(0)  編輯 收藏 引用

            性做久久久久久久久久久| 色综合久久精品中文字幕首页 | 综合久久一区二区三区 | 伊人久久无码中文字幕| 国产美女亚洲精品久久久综合| 精品人妻伦九区久久AAA片69| 久久天天躁狠狠躁夜夜网站| 亚洲国产精品无码久久一区二区| 伊人久久精品无码av一区| 国产日产久久高清欧美一区| 久久久WWW成人| 亚洲va久久久噜噜噜久久男同| 久久91精品国产91久久户| 久久久久久毛片免费看| 中文字幕热久久久久久久| 日本一区精品久久久久影院| 欧美亚洲国产精品久久久久| 日韩精品久久久久久久电影蜜臀| 国产AV影片久久久久久| 一本久道久久综合狠狠爱| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 日韩乱码人妻无码中文字幕久久 | 久久婷婷是五月综合色狠狠| 久久se精品一区精品二区| 99久久免费国产精品特黄| 久久精品国产精品亚洲精品| 国内精品伊人久久久久妇| 国产69精品久久久久99尤物| 亚洲色大成网站WWW久久九九| 精品久久久无码中文字幕| 精品国产VA久久久久久久冰| 久久综合久久性久99毛片| 久久精品免费一区二区三区| 国内精品久久久久影院薰衣草| 欧美亚洲另类久久综合婷婷 | 国产精品九九久久精品女同亚洲欧美日韩综合区 | 久久久久综合中文字幕| 久久天天躁狠狠躁夜夜2020老熟妇| 99国产欧美精品久久久蜜芽| 国内精品综合久久久40p| 久久久久噜噜噜亚洲熟女综合|