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

            健康,快樂,勇敢的寧帥!!

            努力、努力、再努力! 沒有什么能阻止我對知識的渴望。

             

            "C++Templates The Complete Guide"讀書筆記----Chapter 2

            這段時間在通過"C++Templates The Complete Guide"這本書學(xué)習(xí)Templates。發(fā)現(xiàn)這本書確實不錯:語言簡明,內(nèi)容翔實。特別是每章后面的Summery總結(jié)得很好。這份讀書筆記就已這個Summery為基礎(chǔ)寫的。

            書前面的Prefece和Chapter 1就跳過了。既然來學(xué)習(xí)Templates就已經(jīng)知道它的重要性了。

            ??????????????????????????????? Chapter 2 FunctionTemplates
            1. Function templates define a family of functions for different template arguments;

            template? < typename?T >
            inline?T?
            const & ?max?(T? const & ?a,?T? const & ?b)
            {
            ????
            // ?if?a?<?b?then?use?b?else?use?a
            ???? return ??a? < ?b? ? ?b?:?a;
            }

            2. When you pass template arguments, function templates are instantiated for these argument types.
            The process of replacing templates parameters by concrete types is called instantiatin.(at compiled time)
            3. You can explicitly qualify the template parameters

            {
            // ?because?no?automatic?type?conversion?if?allowed?in?templates,so
            max(static_cast < double > ( 4 ), 4.2 ) // cast?the?arguments?so?that?they?both?match
            max < double > ( 4 , 4.2 ) // ?specify?explicitly?the?type?of?T
            }

            4. You can overload funciton templates

            inline? int ? const & ?max?( int ? const & ?a,? int ? const & ?b)?
            {
            ????
            return ??a? < ?b? ? ?b?:?a;
            }


            // ?maximum?of?two?values?of?any?type
            template? < typename?T >
            inline?T?
            const & ?max?(T? const & ?a,?T? const & ?b)
            {
            ????
            return ??a? < ?b? ? ?b?:?a;
            }


            // ?maximum?of?three?values?of?any?type
            template? < typename?T >
            inline?T?
            const & ?max?(T? const & ?a,?T? const & ?b,?T? const & ?c)
            {
            ????
            return ?::max?(::max(a,b),?c);
            }


            int ?main()
            {
            ????::max(
            7 ,? 42 ,? 68 );????? // ?calls?the?template?for?three?arguments
            ????::max( 7.0 ,? 42.0 );????? // ?calls?max<double>?(by?argument?deduction)
            ????::max( ' a ' ,? ' b ' );?????? // ?calls?max<char>?(by?argument?deduction)
            ????::max( 7 ,? 42 );????????? // ?calls?the?nontemplate?for?two?ints
            ????::max <> ( 7 ,? 42 );??????? // ?calls?max<int>?(by?argument?deduction)
            ????::max < double > ( 7 ,? 42 );? // ?calls?max<double>?(no?argument?deduction)
            ????::max( ' a ' ,? 42.7 );????? // ?calls?the?nontemplate?for?two?ints
            }

            ps: the overload resolution process normally prefers this nontemplate over one generated from the template. the fourth call falls under this rule.
            5. When you overload function templates, limit your changes to specifying template parameters explicitly

            {
            max
            <> ( 7 , 42 ); // call?max<int>?(by?argument?deduction)
            }


            6. Make sure you see all overloaded versions of funciton templates before you call them

            template? < typename?T >
            inline?T?
            const & ?max?(T? const & ?a,?T? const & ?b)
            {
            ????
            return ??a? < ?b? ? ?b?:?a;
            }


            // ?maximum?of?three?values?of?any?type
            template? < typename?T >
            inline?T?
            const & ?max?(T? const & ?a,?T? const & ?b,?T? const & ?c)
            {
            ????
            return ?max?(max(a,b),?c);?? // ?uses?the?template?version?even?for?ints
            }
            ?????????????????????????????? // ?because?the?following?declaration?comes
            ???????????????????????????????
            // ?too?late:
            // ?maximum?of?two?int?values
            inline? int ? const & ?max?( int ? const & ?a,? int ? const & ?b)?
            {
            ????
            return ??a? < ?b? ? ?b?:?a;
            }


            ?

            posted on 2006-11-26 15:24 ningfangli 閱讀(179) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計

            公告

            Dict.CN 在線詞典, 英語學(xué)習(xí), 在線翻譯

            常用鏈接

            留言簿(4)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产成人久久激情91| 国产精品美女久久福利网站| 中文字幕精品久久| 久久精品国产精品亜洲毛片 | 日本精品久久久久中文字幕| 久久狠狠爱亚洲综合影院| 久久笫一福利免费导航| 婷婷久久精品国产| 亚洲国产日韩综合久久精品| 亚洲精品视频久久久| 久久午夜福利无码1000合集| 久久婷婷色香五月综合激情| 一本大道久久东京热无码AV | 国产成人精品免费久久久久| 久久久久99精品成人片欧美| 99久久精品毛片免费播放| 国产精品久久久久天天影视| 国产AⅤ精品一区二区三区久久| 国产—久久香蕉国产线看观看| 久久久久无码国产精品不卡| 无码国内精品久久综合88| 婷婷久久久亚洲欧洲日产国码AV | 精品国产青草久久久久福利| 亚洲伊人久久综合影院| 亚洲伊人久久精品影院| www.久久热.com| 久久这里只精品国产99热| 大伊人青草狠狠久久| 久久国产视屏| 亚洲AV无码久久精品蜜桃| 久久99精品久久久久久| 青青热久久国产久精品 | 国产成人无码精品久久久性色| 色狠狠久久AV五月综合| 国内精品久久久久久久coent| 亚洲日本va午夜中文字幕久久| 亚洲国产精品久久电影欧美| 久久99精品久久久久久野外| 无码人妻精品一区二区三区久久 | 欧美粉嫩小泬久久久久久久| 久久久久久午夜精品|