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

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久久97| 久久99精品免费一区二区| 久久午夜综合久久| 一本色道久久综合亚洲精品| 婷婷久久久亚洲欧洲日产国码AV | 欧美亚洲国产精品久久| 久久精品人人槡人妻人人玩AV| 久久精品人人做人人爽97| 久久伊人中文无码| 粉嫩小泬无遮挡久久久久久 | 欧美丰满熟妇BBB久久久| 久久久久亚洲?V成人无码| 99久久精品午夜一区二区 | 国产香蕉久久精品综合网| 国产精品成人精品久久久| 色综合久久无码中文字幕| 久久精品免费大片国产大片| 精品免费久久久久久久| 久久久久高潮综合影院| 久久亚洲AV无码精品色午夜麻豆| 久久久久久狠狠丁香| 亚洲午夜久久久影院| 亚洲第一永久AV网站久久精品男人的天堂AV| 精品九九久久国内精品| 国产精品一久久香蕉国产线看| 午夜精品久久久久久毛片| 久久无码精品一区二区三区| 97超级碰碰碰碰久久久久| 丰满少妇人妻久久久久久4| 久久ww精品w免费人成| 九九精品99久久久香蕉| 人妻少妇久久中文字幕| 久久人妻少妇嫩草AV无码专区| 精品久久久久久久久免费影院| 一本久久免费视频| 人妻丰满AV无码久久不卡| 人妻精品久久无码区| 久久天堂AV综合合色蜜桃网 | 国产成人精品久久| 一本色综合网久久| 久久精品www人人爽人人|