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

            liyuxia713

            蹣跚前行者

            常用鏈接

            統(tǒng)計

            Algorithms

            C++

            最新評論

            [導(dǎo)入]模板編譯模型

            1.包含編譯模型(inclusion compilation model). 函數(shù)聲明放在頭文件中,定義放在源文件中。頭文件尾包含源文件。據(jù)說會出現(xiàn)一個模板實例化多次從而導(dǎo)致編譯時性能顯著降低。

            //template.cpp
            template<typename T>
            void print(const T &v)
            {
                cout << "T = " << v <<endl;
            }

            //template.h
            #ifndef TEMPLATE_H
            #define TEMPLATE_H

            template<typename T>
            void print(const T &v);

            #include "template.cpp" 

            #endif

            //main.cpp
            #include<iostream>
            #include "template.h"  
            //#include"template.cpp" 用這條命令代替也可以。

            using namespace std;

            int main()
            {
               
            print(1); //ok
                return 0;
            }

            2. 分別編譯模型(seperate compilation model).函數(shù)聲明和類定義放在頭文件中,帶export關(guān)鍵字的函數(shù)定義和類聲明放在源文件中。源文件尾包含頭文件。(不知道理解的對不對,用的編譯器不支持分別編譯,暫時無從判斷了

            //the template definition goes in a separately-compiled source file

            export template<typename T>

            T print(const T&v) /*...*/

            //class template header goes in shared header file

            template <class T> class cl{...};

            //cl.cpp implementation file declares cl as exported

            export template <class T> class cl;

            #include "cl.h"

            //cl member definitions


            文章來源:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!265.entry

            posted on 2009-03-24 15:50 幸運草 閱讀(509) 評論(0)  編輯 收藏 引用 所屬分類: C++

            久久午夜综合久久| 国产麻豆精品久久一二三| 国产福利电影一区二区三区,免费久久久久久久精 | 国产精品久久久久久福利漫画| 久久精品国产精品青草app| 国产—久久香蕉国产线看观看| 久久久WWW免费人成精品| 亚洲精品第一综合99久久| 久久中文骚妇内射| 精品国产综合区久久久久久 | 久久精品三级视频| 伊人色综合久久天天人手人婷| 久久大香香蕉国产| 久久婷婷五月综合97色直播| 久久无码人妻一区二区三区午夜| 91精品国产91久久久久久青草| 久久热这里只有精品在线观看| 国产成人精品久久一区二区三区av| 一日本道伊人久久综合影| 亚洲国产精品热久久| 久久精品国产亚洲av麻豆图片| 99久久精品国产一区二区蜜芽| 亚洲中文字幕久久精品无码喷水| 久久九九免费高清视频| 青青青伊人色综合久久| 人妻精品久久无码专区精东影业| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区| 色欲久久久天天天综合网精品 | 久久久久人妻一区精品色| 人妻无码精品久久亚瑟影视| 久久久久无码精品| 国产成人无码精品久久久久免费 | 久久精品综合网| 久久性精品| 亚洲人AV永久一区二区三区久久| 国产精品内射久久久久欢欢| 久久国产精品久久国产精品| 九九99精品久久久久久| 精品午夜久久福利大片| 99久久精品这里只有精品| 精品精品国产自在久久高清|