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

            蹣跚前行者

            常用鏈接

            統計

            Algorithms

            C++

            最新評論

            [導入]模板編譯模型

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

            //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).函數聲明和類定義放在頭文件中,帶export關鍵字的函數定義和類聲明放在源文件中。源文件尾包含頭文件。(不知道理解的對不對,用的編譯器不支持分別編譯,暫時無從判斷了

            //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 幸運草 閱讀(523) 評論(0)  編輯 收藏 引用 所屬分類: C++

            久久久无码人妻精品无码| 久久精品国产亚洲av麻豆小说| 9999国产精品欧美久久久久久| 久久综合综合久久97色| 青青久久精品国产免费看| 久久这里只有精品18| 久久国产一区二区| 无码人妻久久一区二区三区蜜桃 | 亚洲欧洲精品成人久久曰影片 | 久久黄色视频| 久久午夜伦鲁片免费无码| 99久久99久久精品国产片| 亚洲av伊人久久综合密臀性色 | 国产精品无码久久综合| 性做久久久久久久久老女人| 国产精品久久久久久福利漫画 | 精品蜜臀久久久久99网站| 国产精品乱码久久久久久软件| 99久久国产综合精品成人影院| 久久九九精品99国产精品| 久久亚洲AV无码精品色午夜 | 久久精品无码专区免费青青| 亚洲精品无码久久久| 久久精品国产99国产精品| 四虎国产永久免费久久| 97久久天天综合色天天综合色hd| 国产色综合久久无码有码| 亚洲国产精品无码久久九九| 精品无码久久久久久久动漫| 国产激情久久久久影院| 一本大道加勒比久久综合| 成人午夜精品久久久久久久小说| 2021少妇久久久久久久久久| 久久国产免费观看精品| 久久天堂电影网| 国产亚洲色婷婷久久99精品91| 国内精品久久久久久久久电影网| 国产成人久久精品麻豆一区| 久久久艹| 亚洲AV无码一区东京热久久| 午夜人妻久久久久久久久|