• <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)  編輯 收藏 引用

            久久毛片免费看一区二区三区| 久久久精品波多野结衣| 亚洲中文字幕伊人久久无码| 国产精品一区二区久久精品涩爱| 国产精品99久久久久久宅男小说| 久久青青草原亚洲av无码app | 久久99久国产麻精品66| 亚洲va中文字幕无码久久不卡| www.久久精品| 久久精品综合网| 久久综合综合久久狠狠狠97色88| 欧美亚洲国产精品久久久久| 国产午夜精品理论片久久影视| 人妻精品久久久久中文字幕 | 99久久国产免费福利| 一本色道久久88—综合亚洲精品 | 性高湖久久久久久久久AAAAA| 久久99国产综合精品| 亚洲国产精品狼友中文久久久| 老司机国内精品久久久久| 久久精品天天中文字幕人妻 | 久久男人AV资源网站| 999久久久免费精品国产| 国内精品久久久久影院亚洲| 久久人人爽人人澡人人高潮AV| 精品久久久久久久| 久久偷看各类wc女厕嘘嘘| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 欧美一区二区久久精品| 久久精品成人| 国产精品伦理久久久久久| 欧美综合天天夜夜久久| 国产精品久久久久久吹潮| 久久无码人妻一区二区三区午夜| 囯产极品美女高潮无套久久久| 亚洲国产精品一区二区三区久久| 久久精品国产亚洲Aⅴ蜜臀色欲| 国产AⅤ精品一区二区三区久久| 94久久国产乱子伦精品免费| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 亚洲乱码日产精品a级毛片久久 |