• <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 閱讀(274) 評論(0)  編輯 收藏 引用 所屬分類: C++基礎

            導航

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

            留言簿(6)

            隨筆分類(109)

            隨筆檔案(105)

            Blogers

            Game

            Life

            NodeJs

            Python

            Useful Webs

            大牛

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久亚洲AV成人网人人网站 | 久久久噜噜噜久久| 久久免费大片| 精品久久亚洲中文无码| www久久久天天com| 人妻精品久久久久中文字幕| 狠狠色综合网站久久久久久久高清| 亚洲午夜久久久影院伊人| 久久91精品国产91久久户| 亚洲国产精品综合久久网络| 精品人妻久久久久久888| 日韩电影久久久被窝网| 国产精品久久久久天天影视| 精品免费久久久久国产一区| 色婷婷久久综合中文久久蜜桃av| 国产成人精品久久亚洲高清不卡| 亚洲va久久久噜噜噜久久天堂| 久久精品国产精品亚洲下载| 性欧美大战久久久久久久久| 狠狠色综合久久久久尤物| 精品蜜臀久久久久99网站| 久久久一本精品99久久精品88| 国产91久久综合| 97精品国产91久久久久久| 亚洲精品乱码久久久久久久久久久久 | 久久国产亚洲精品| 国产99久久久国产精品~~牛| 久久99国产综合精品女同| 亚洲va久久久噜噜噜久久 | 久久久久国产精品熟女影院| 亚洲精品无码专区久久同性男| 国产免费久久精品99久久| 品成人欧美大片久久国产欧美...| 国内精品九九久久久精品| 久久A级毛片免费观看| 99久久精品午夜一区二区| 99久久久精品| 国产精品伊人久久伊人电影| 岛国搬运www久久| 日批日出水久久亚洲精品tv| 久久婷婷五月综合成人D啪|