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

            導航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            留言簿(6)

            隨筆分類(109)

            隨筆檔案(105)

            Blogers

            Game

            Life

            NodeJs

            Python

            Useful Webs

            大牛

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            成人妇女免费播放久久久| 综合久久一区二区三区| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 99久久精品免费看国产免费| 好久久免费视频高清| 久久久久亚洲AV无码专区网站| 日日狠狠久久偷偷色综合0| 久久精品国产男包| 国产成人久久激情91 | 国内精品九九久久精品| 国产精品禁18久久久夂久| 精品国产91久久久久久久a| 国产成人精品久久| 久久男人AV资源网站| 国产精品久久久久久久| 久久人人爽人人爽人人片AV不| 久久精品国产亚洲麻豆| 2019久久久高清456| 国内精品欧美久久精品| 久久人人爽人人爽人人AV| 久久久WWW成人| 91精品观看91久久久久久| 欧美va久久久噜噜噜久久| 久久婷婷人人澡人人| 国产女人aaa级久久久级| 成人久久综合网| 精品久久久久久国产潘金莲| 久久无码AV中文出轨人妻| 久久综合伊人77777| 久久精品成人一区二区三区| 99久久精品国产高清一区二区 | 久久精品一区二区三区不卡| 亚洲AV无码久久| 久久久一本精品99久久精品88| 久久精品综合一区二区三区| 国产69精品久久久久99| 久久被窝电影亚洲爽爽爽| 99久久99久久精品免费看蜜桃| 亚洲熟妇无码另类久久久| 久久精品国产精品亚洲精品| 丁香色欲久久久久久综合网|