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

            luqingfei@C++

            為中華之崛起而崛起!
            兼聽則明,偏聽則暗。

            關于函數模板及其重載的練習

            #include <iostream>
            #include 
            <string>
            using std::cout;
            using std::endl;
            using std::string;

            //Template function prototype
            template<class T> T plus(const T& a, const T& b);
            string plus(const string& a, const string& b);

            void main() {
                cout 
            << "plus(3, 4) = " << plus(34<< endl;
                cout 
            << "plus(3.2, 4.2) = " << plus(3.24.2<< endl;
                cout 
            << "plus(\"he\", \"llo\") = " << plus(static_cast<string>("he"), static_cast<string>("llo")) << endl;
                
                cout 
            << "plus(static_cast<double>(3), 4.2) = " << plus(static_cast<double>(3), 4.2<< endl;
                cout 
            << "plus(3, static_cast<int>(4.2)) = " << plus(3, static_cast<int>(4.2)) << endl;

            }

            template
            <class T> T plus(const T& a, const T& b) {
                
            return a + b;
            }

            string plus(const string& a, const string& b) {
                cout 
            << "specifica" << endl;
                
            return a + b;
            }

            運行結果:
            plus(3, 4) = 7
            plus(3.2, 4.2) = 7.4
            specifica
            plus("he", "llo") = hello
            plus(static_cast<double>(3), 4.2) = 7.2
            plus(3, static_cast<int>(4.2)) = 7

            posted on 2009-02-13 17:53 luqingfei 閱讀(275) 評論(0)  編輯 收藏 引用 所屬分類: C++基礎

            導航

            <2010年7月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            留言簿(6)

            隨筆分類(109)

            隨筆檔案(105)

            Blogers

            Game

            Life

            NodeJs

            Python

            Useful Webs

            大牛

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            香蕉aa三级久久毛片| 亚洲精品乱码久久久久久蜜桃图片| 久久久久久久亚洲Av无码| 99国产欧美久久久精品蜜芽| 国产精品久久久久影视不卡| 国产高潮久久免费观看| 亚洲欧美另类日本久久国产真实乱对白 | 91精品国产综合久久香蕉| 麻豆久久| 久久久久国产精品| 免费一级做a爰片久久毛片潮| 亚洲AV无一区二区三区久久| 97精品国产97久久久久久免费 | 一本色道久久88精品综合| 久久99免费视频| 99精品国产综合久久久久五月天| 久久精品一区二区国产| 伊人久久大香线蕉综合热线| 久久国产乱子伦精品免费强| 久久国产免费| 精品久久一区二区| 无码人妻精品一区二区三区久久久| 国产福利电影一区二区三区久久久久成人精品综合 | 久久久久综合国产欧美一区二区| 久久精品国产亚洲AV香蕉| 四虎国产精品免费久久| 久久精品成人免费国产片小草| 久久国产亚洲精品无码| 亚洲伊人久久精品影院| 亚洲国产精品嫩草影院久久 | 国内精品久久久久久久久电影网| 久久久久国色AV免费观看| 四虎国产精品免费久久5151| 国产精品久久久久久福利69堂| 伊人久久精品无码av一区| 久久人人添人人爽添人人片牛牛| 久久人妻少妇嫩草AV无码蜜桃| 久久精品国产一区二区三区| 精品久久久无码中文字幕| 国产精品综合久久第一页| 国産精品久久久久久久|