• <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。發現這本書確實不錯:語言簡明,內容翔實。特別是每章后面的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)  編輯 收藏 引用

            導航

            統計

            公告

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

            常用鏈接

            留言簿(4)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品久久久久观看99水蜜桃| 国产日韩欧美久久| 无码精品久久一区二区三区 | 99精品国产免费久久久久久下载| 色婷婷噜噜久久国产精品12p| 狠狠色噜噜色狠狠狠综合久久| 久久精品毛片免费观看| 久久精品国产第一区二区| 国内精品伊人久久久久777| 91精品婷婷国产综合久久 | 青春久久| 国产精品久久久久久久久| 久久伊人中文无码| 国产精品久久网| 一本大道久久香蕉成人网| 国产精品毛片久久久久久久| 波多野结衣久久一区二区| 岛国搬运www久久| 久久久久成人精品无码中文字幕 | www.久久热| 亚洲AV无码久久精品蜜桃| 国产精品久久久99| 久久96国产精品久久久| 奇米综合四色77777久久| 久久中文字幕视频、最近更新| 国产Av激情久久无码天堂| 久久人妻无码中文字幕| 亚洲精品高清一二区久久| 国产精品综合久久第一页| 久久久久久免费一区二区三区| 色欲综合久久中文字幕网| 久久精品国产亚洲AV蜜臀色欲| 深夜久久AAAAA级毛片免费看 | 久久经典免费视频| 热综合一本伊人久久精品 | AAA级久久久精品无码片| 伊人久久无码中文字幕| 久久精品国产亚洲av麻豆蜜芽| 一本色道久久88精品综合| 久久久久亚洲AV无码专区首JN| 久久综合久久综合亚洲|