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

            Edgard

            2005年12月15日 #

            討論FunctionTemplate申明的隱藏性(Visibility)

            看看兩端代碼,區別重要在:
            一個是:inline int const& max申明在template <typename T>
            inline T const& max之前。


            // maximum of two int values
            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); 
            }                              

            一個是:inline int const& max申明在template <typename T>
            inline T const& max之后。

            // 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); 
            }

            // maximum of two int values
            inline int const& max (int const& a, int const& b)
            {
                return a<b?b:a;
            }

            調用程序:
            int main( )
            {
                  //當然這里本來就寫得不好,要先顯式申明寫局部變量......
                  // 看你了解多少,討論討論兩種執行可能的執行路徑,即:FunctionTemplate的調用路徑?。?!
                  ::max( 4, 10 ,15 );


            posted @ 2005-12-15 21:10 Edgard 閱讀(531) | 評論 (5)編輯 收藏

            VC編譯器對FunctionTemplate實例化的優化

            VC編譯器對FunctionTemplate實例化的優化:
            看下面Template代碼:

            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);
            }

            inline int const& max (int const& a, int const& b) 已經是template <typename T>
            inline T const& max (T const& a, T const& b) 對類型int的實例化,所以,凡是需要調用max<int>時,VC 編譯器都不在再用max<int>來Instantiate max Function Template.


            int main ()

                ::max(7, 42, 68); // calls the template for three arguments first, then call inline int const& max   
                   

                ::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);  // call inline int const& max
                ::max<int>(7, 42); // call inline int const& max
                ::max<int>(7.0, 42.0); // call inline int const& max
                ::max<double>(7, 42); // calls max<double> (no argument deduction)

               return 0;
            }

            posted @ 2005-12-15 20:43 Edgard 閱讀(563) | 評論 (2)編輯 收藏

            僅列出標題  
            狠狠色婷婷久久综合频道日韩| 无码日韩人妻精品久久蜜桃| 国产亚洲色婷婷久久99精品91| 久久精品无码一区二区app| 亚洲国产精品综合久久网络 | 国内精品久久久久影院优| 国产精品内射久久久久欢欢| 欧美亚洲另类久久综合婷婷| 婷婷五月深深久久精品| 久久天天躁狠狠躁夜夜不卡| 久久精品夜夜夜夜夜久久| 欧美久久久久久午夜精品| 99久久无码一区人妻a黑| 久久91精品国产91| 国产精品免费久久久久久久久| 国内精品久久久久影院薰衣草 | 日韩精品久久久肉伦网站| 久久精品中文字幕有码| www久久久天天com| 久久精品国产乱子伦| 久久这里只有精品视频99| 狠狠久久亚洲欧美专区| 欧美一区二区三区久久综合| 久久久免费观成人影院| 久久国产精品-国产精品| 人妻无码αv中文字幕久久琪琪布| 久久免费视频6| 久久国产三级无码一区二区| 久久九九全国免费| 久久成人影院精品777| 久久er国产精品免费观看2| jizzjizz国产精品久久| 国产精品美女久久久m| 久久精品国产亚洲AV电影 | 日本免费久久久久久久网站| 69国产成人综合久久精品| 久久亚洲美女精品国产精品| 精品乱码久久久久久久| 国产精品对白刺激久久久| 久久发布国产伦子伦精品| 蜜桃麻豆www久久|