青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

健康,快樂,勇敢的寧帥!!

努力、努力、再努力! 沒有什么能阻止我對知識(shí)的渴望。

 

"C++Templates The Complete Guide"讀書筆記----Chapter 6

Using Templates in Practice

1. Templates challenge the classic compiler-plus-linker model. Therefore there are different approaches to organize template code: the inclusion model, explicit instantiation, and the separation model
Most C and C++ programmers organize their nontemplate code largely as follows:
1) Classes and other types are entirely placed in header files.
2) For global variables and (noninline) functions, only a declaration is put in a header file, and the definition goes into a so-called dot-C file.
The works well: It makes the needed type definition easily available throughout the program and avoids duplicate definition errors on variables and functions from the linker.
With the convention in mind, we declare the template in a header file:
#ifndef?MYFIRST_HPP
#define?MYFIRST_HPP

//?declaration?of?template
template?<typename?T>?
void?print_typeof?(T?const&);

#endif?//?MYFIRST_HPP
The implementation of the function is placed in a dot-C file:
#include?<iostream>
#include?
<typeinfo>
#include?
"myfirst.hpp"

//?implementation/definition?of?template
template?<typename?T>
void?print_typeof?(T?const&?x)
{
????std::cout?
<<?typeid(x).name()?<<?std::endl;
}
Finally, we use the template in another dot-C file, into which our template declaration is #include:
#include?"myfirst.hpp"

//?use?of?the?template
int?main()
{
????
double?ice?=?3.0;
????print_typeof(ice);??
//?call?function?template?for?type?double
}

A C++ compiler will most likely accept this program without any problems,but the linker will probably report an error, implying that there is no definition of the function print_typeof().
In order for a template to be? instantiated, the compiler must know which definition should be instantiated and for what template arguments it should be instantiated. Unfortunately, these two pieces of information are in files that are compiled separatedly. Therefore, when our compiler sees the call to print_typeof() but has no definition in sight to instantiate this function for double, it just assumes that such a definition is provided elsewhere and creates a reference(for the linker to resolve,linker) to that definition. On the other hand, when the compiler processes the file myfirst.cpp, it has no indication at that point that it must instantiate the template definition it contains for specific arguments.

The Inclusion Model
Rewrite the header-file, including template definition.
#ifndef?MYFIRST_HPP
#define?MYFIRST_HPP


#include?
<iostream>
#include?
<typeinfo>

//?declaration?of?template
template?<typename?T>?
void?print_typeof?(T?const&
);

//?implementation/definition?of?template

template?<typename?T>
void?print_typeof?(T?const&?x)
{
????std::cout?
<<?typeid(x).name()?<<
?std::endl;
}


#endif?//?MYFIRST_HPP
disadvantage: the cost is not the result of size of the template definition itself, but the result of the fact that we must also include the header used by the definition of our template-in the case <iostream> and <typeinfo>.\

Explicit Instantiation
To avoid above linker error we can add the following file to our program:
#include?"myfirst.cpp"

//?explicitly?instantiate?print_typeof()?for?type?double
template?void?print_typeof<double>(double?const&);
disadvantage: We must carefully keep track of which entities to instantiate. For large projects this quickly becomes an excessive burden.
advantage:
the instantiation can be tuned to the needs of the program.
The overhead of large header is avoided.
The source code of template definition can be kept hidden, but then no additional instantiations can be created by a client program.
Finally, for some applications it can be useful to control the exact location(that is, the object file)of a template instance.

Separation model

2. Usually you should use the inclusion model
3. By separating template code into different header files for declarations and definitions, you can more easily switch between the inclusion model and explicit instantiation
4. The C++ standard defines a separate compilation model for templates(using the keyword export). It is not yet widely available, however.
5. To take advantage of precompiled headers, be sure to keep the same order for #include directives.
6. Debuggin code with templates can be challenging
7. Template instances may have very long names

posted on 2006-12-03 12:38 ningfangli 閱讀(183) 評論(0)  編輯 收藏 引用

導(dǎo)航

統(tǒng)計(jì)

公告

Dict.CN 在線詞典, 英語學(xué)習(xí), 在線翻譯

常用鏈接

留言簿(4)

隨筆檔案

文章分類

文章檔案

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久这里只有精品视频首页| 国产精品自拍网站| 中文精品视频| 亚洲精品乱码久久久久久黑人| 欧美一区成人| 欧美亚洲日本网站| 久久激情网站| 欧美激情久久久久久| 亚洲欧洲日本一区二区三区| 欧美激情一区二区在线 | 欧美四级伦理在线| 欧美日本视频在线| 国产伦精品一区二区三区| 一区二区三区www| 欧美一区日本一区韩国一区| 亚洲男女毛片无遮挡| 香蕉久久夜色精品| 免费观看成人| 国产精品久久久久av| 国产一区二区三区高清| 亚洲国产日韩在线| 国产精品99久久久久久久女警 | 亚洲香蕉成视频在线观看| 亚洲一区免费看| 久久中文字幕一区| 亚洲欧洲日韩在线| 欧美一级免费视频| 欧美精品一区二区三区四区| 国产精品日韩在线观看| 亚洲国产日日夜夜| 久久国产欧美精品| 亚洲精品一区二区在线观看| 午夜在线观看免费一区| 欧美片第一页| 伊人久久av导航| 亚洲一区日本| 亚洲国产精品电影| 香蕉成人啪国产精品视频综合网| 欧美成人免费在线观看| 国产日韩欧美精品| 亚洲午夜激情网站| 欧美国产在线视频| 久久精品国产在热久久| 国产精品成人国产乱一区 | 久久久国产精品亚洲一区 | 亚洲美女视频在线观看| 欧美在线不卡| 一区二区三区国产盗摄| 欧美黄色免费| 亚洲激情影院| 免费亚洲视频| 欧美一区二区三区在线免费观看| 欧美日韩一区不卡| 日韩亚洲欧美一区| 亚洲国产精品一区二区www| 久久精品人人爽| 国产亚洲精品aa| 欧美中文字幕久久| 亚洲制服丝袜在线| 国产精品视频九色porn| 亚洲欧美日韩在线一区| 中文日韩在线视频| 亚洲精品欧美日韩| 欧美大胆人体视频| 日韩视频一区二区在线观看| 欧美国产视频在线| 欧美激情精品久久久久久免费印度 | 毛片一区二区三区| 在线观看欧美视频| 免费影视亚洲| 免费在线一区二区| 日韩午夜中文字幕| 亚洲精品免费网站| 欧美先锋影音| 欧美在线免费播放| 久久精品99国产精品日本| 韩国三级电影久久久久久| 久久婷婷国产综合精品青草 | 欧美中文在线观看| 伊人色综合久久天天| 男人的天堂成人在线| 欧美v亚洲v综合ⅴ国产v| 亚洲精品在线免费| 一区二区三区欧美激情| 国产精品麻豆欧美日韩ww| 香蕉国产精品偷在线观看不卡 | 亚洲欧美国产精品桃花| 国产一区二区三区高清播放| 裸体一区二区| 欧美日韩国产片| 久久国产精品72免费观看| 久久这里只有精品视频首页| 日韩一级片网址| 香蕉成人啪国产精品视频综合网| 亚洲第一黄色| 亚洲一区二区在线观看视频| 在线观看日韩欧美| 一区二区三区欧美在线| 激情小说另类小说亚洲欧美| 亚洲国产成人一区| 国产精品视频yy9099| 欧美大片免费观看| 国产精品一二三视频| 亚洲国产91| 国产日韩综合| 99re6这里只有精品| 国产性天天综合网| 亚洲免费成人| 亚洲国产精品t66y| 亚洲一区二区在线免费观看视频| 亚洲激情网站| 欧美在线国产精品| 亚洲欧美精品| 欧美连裤袜在线视频| 免费91麻豆精品国产自产在线观看| 欧美日韩国产精品一区| 99精品99| 久久久久久久久综合| 亚洲国产欧美日韩精品| 国产精品美女久久久| 亚洲激情av| 在线观看日韩欧美| 欧美中文字幕不卡| 欧美一区二区三区免费大片| 欧美高清在线视频| 欧美xxx成人| 黄色一区二区三区四区| 性色av一区二区怡红| 亚洲欧美日韩中文在线制服| 欧美激情女人20p| 亚洲高清二区| 亚洲国产另类久久精品| 久久九九精品99国产精品| 久久精品国产第一区二区三区最新章节 | 最新中文字幕亚洲| 亚洲激情成人| 久久一区二区三区四区| 久久婷婷国产综合国色天香| 国产区精品视频| 午夜久久久久| 久久婷婷蜜乳一本欲蜜臀| 国产女主播一区二区三区| 亚洲一区二区免费视频| 欧美一级片久久久久久久| 国产精品a级| 亚洲午夜久久久久久久久电影院| 国产精品99久久久久久宅男| 欧美日韩视频专区在线播放| 日韩视频免费观看| 亚洲在线视频观看| 国产毛片久久| 久久精品中文字幕免费mv| 美女免费视频一区| 亚洲精品视频一区| 欧美日韩一区二| 亚洲一区观看| 久久亚洲国产精品日日av夜夜| 国内自拍视频一区二区三区| 久久夜色精品国产欧美乱| 亚洲高清中文字幕| 亚洲视频网站在线观看| 国产精品美女久久久浪潮软件 | 欧美日本不卡视频| 亚洲在线播放电影| 美女精品网站| 99综合在线| 国产精品有限公司| 老司机一区二区三区| 日韩网站在线观看| 久久精品国产一区二区电影| 伊人精品在线| 欧美性事在线| 久久午夜电影| 在线一区二区三区四区| 可以免费看不卡的av网站| 一区二区三区精密机械公司| 国产精品免费视频观看| 久久一区二区三区国产精品| 亚洲一区在线免费观看| 精品999日本| 欧美三级午夜理伦三级中文幕| 午夜一级久久| 亚洲精品国偷自产在线99热| 久久精品91久久香蕉加勒比| 亚洲美洲欧洲综合国产一区| 国产日韩在线视频| 欧美日韩综合精品| 久久婷婷av| 亚洲免费视频网站| 亚洲精华国产欧美| 欧美一级视频一区二区| 91久久精品网| 狠狠爱www人成狠狠爱综合网| 欧美日韩一级片在线观看| 欧美成人亚洲成人| 久久午夜av| 久久精品欧美日韩精品| 亚洲欧美久久久久一区二区三区| 亚洲福利一区| 麻豆freexxxx性91精品|