• <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"這本書學習Templates。發(fā)現(xiàn)這本書確實不錯:語言簡明,內容翔實。特別是每章后面的Summery總結得很好。這份讀書筆記就已這個Summery為基礎寫的。

            書前面的Prefece和Chapter 1就跳過了。既然來學習Templates就已經知道它的重要性了。

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

            導航

            統(tǒng)計

            公告

            Dict.CN 在線詞典, 英語學習, 在線翻譯

            常用鏈接

            留言簿(4)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久99精品久久久久久水蜜桃| 色婷婷噜噜久久国产精品12p| 少妇精品久久久一区二区三区| 久久人人爽人人爽人人AV| 婷婷五月深深久久精品| 嫩草影院久久99| 无码国内精品久久人妻麻豆按摩| 亚洲性久久久影院| 久久亚洲精品中文字幕| 热RE99久久精品国产66热| 久久成人国产精品免费软件| 久久综合综合久久狠狠狠97色88| 久久人人添人人爽添人人片牛牛 | 久久精品中文字幕一区| 久久精品国产免费观看 | 精品久久久久久| 久久国产亚洲精品| 国产精品99久久久久久宅男 | 成人妇女免费播放久久久| 日本精品一区二区久久久| 国产成人无码久久久精品一| 99久久综合国产精品免费| 久久99久久无码毛片一区二区| 99国产欧美久久久精品蜜芽| 无码国内精品久久综合88| 久久久精品视频免费观看| 久久精品无码一区二区三区| 久久久久99精品成人片欧美| 99久久香蕉国产线看观香| 婷婷久久综合九色综合九七| 久久夜色精品国产www| 国产精久久一区二区三区| 国产精品内射久久久久欢欢| 久久99国产精品尤物| 久久国产精品成人片免费| 久久久精品国产sm调教网站 | 91亚洲国产成人久久精品网址| 久久99国产精品久久99果冻传媒| 久久久国产精品亚洲一区| AAA级久久久精品无码片| 青青草原精品99久久精品66 |