• <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 閱讀(515) | 評論 (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 閱讀(551) | 評論 (2)編輯 收藏

            僅列出標題  
            www.久久热| 久久亚洲AV无码精品色午夜麻豆| 久久亚洲AV无码西西人体| 国产一区二区精品久久凹凸| 久久精品成人一区二区三区| 无遮挡粉嫩小泬久久久久久久| 狠狠88综合久久久久综合网| 激情久久久久久久久久| 亚洲国产成人精品无码久久久久久综合 | 麻豆av久久av盛宴av| 精品熟女少妇av免费久久| 久久精品成人一区二区三区| 久久99久久99精品免视看动漫| 国产精品欧美久久久久天天影视| 久久妇女高潮几次MBA| 欧美粉嫩小泬久久久久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 久久综合久久久| 九九久久自然熟的香蕉图片| 四虎久久影院| 精品久久久久久久久久久久久久久 | 久久精品国产2020| 思思久久99热只有频精品66| 久久99久久无码毛片一区二区| 久久久精品人妻一区二区三区四| 2021最新久久久视精品爱| 99久久精品免费看国产| 香港aa三级久久三级| 久久精品水蜜桃av综合天堂| 久久受www免费人成_看片中文| 久久精品国产72国产精福利| 国产成人无码精品久久久久免费 | 伊人精品久久久久7777| 久久人人爽人人爽人人片AV麻豆| 久久电影网2021| 久久精品国产亚洲Aⅴ香蕉 | 激情久久久久久久久久| 91久久成人免费| 久久精品国产WWW456C0M| 久久一区二区三区99| 亚洲国产成人久久精品99 |