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

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

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

 

"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)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


導(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>
            久久蜜桃精品| 亚洲日韩欧美视频| 亚洲国产精品成人久久综合一区| 国产亚洲毛片| 国内精品免费在线观看| 国产精品揄拍一区二区| 国产精品尤物| 亚洲第一福利视频| 99热这里只有成人精品国产| 制服丝袜亚洲播放| 欧美淫片网站| 亚洲丰满在线| 在线亚洲欧美视频| 久久福利精品| 欧美午夜欧美| 亚洲国产成人av| 久久精品国产在热久久| 欧美日本中文| 欧美午夜剧场| 一区精品久久| 一本久久精品一区二区| 欧美一区高清| 亚洲国产日韩精品| 亚洲资源av| 免费观看成人网| 国产精品久久久久久模特| 一区二区视频欧美| 亚洲香蕉在线观看| 欧美高清在线视频| 亚洲一本视频| 欧美成人免费全部| 国产日韩精品一区观看| 亚洲精品在线一区二区| 久久久噜噜噜久噜久久| 一区二区欧美精品| 欧美mv日韩mv国产网站app| 国产欧美精品在线播放| 一区二区三区欧美| 欧美激情一区二区久久久| 午夜精品久久久久久久白皮肤| 另类综合日韩欧美亚洲| 国产欧美高清| 午夜精品国产更新| 99re6这里只有精品视频在线观看| 久久久综合精品| 激情懂色av一区av二区av| 午夜精品视频在线观看| 亚洲精品久久久蜜桃| 免费亚洲电影在线观看| 一区精品久久| 麻豆av一区二区三区| 欧美伊人久久久久久午夜久久久久| 国产精品激情电影| 亚洲无线一线二线三线区别av| 亚洲国产三级在线| 你懂的国产精品| 亚洲精品在线三区| 日韩视频在线观看免费| 欧美日韩伊人| 午夜精品999| 欧美一二区视频| 红桃av永久久久| 免费日韩成人| 欧美大尺度在线| 99riav久久精品riav| 亚洲人成欧美中文字幕| 欧美精品色一区二区三区| 一本大道久久a久久精二百| 亚洲日本激情| 欧美性片在线观看| 欧美在线免费播放| 欧美一级在线亚洲天堂| 狠狠久久五月精品中文字幕| 久久综合电影| 久久亚洲色图| 久久国产精品久久久久久| 亚洲欧美日韩国产| 亚洲一区欧美激情| 国产亚洲精品一区二区| 麻豆精品国产91久久久久久| 久久一区免费| avtt综合网| 亚洲一区二区三区激情| 国产欧美精品在线播放| 免费在线观看日韩欧美| 欧美欧美天天天天操| 亚洲欧美一区二区三区久久| 欧美一区二区三区视频免费播放| 一区二区三区在线观看国产| 欧美激情综合| 国产欧美日韩视频在线观看| 久久综合色播五月| 欧美激情中文不卡| 久久爱www久久做| 久久综合中文字幕| 亚洲在线视频| 久久精品视频免费播放| 亚洲精品裸体| 新67194成人永久网站| 亚洲看片一区| 久久三级视频| 欧美影院一区| 欧美破处大片在线视频| 久久一二三区| 国产精品毛片a∨一区二区三区| 狂野欧美激情性xxxx欧美| 欧美激情第9页| 麻豆精品网站| 国产欧美在线视频| 亚洲免费av观看| 亚洲激情视频在线| 久久久99精品免费观看不卡| 亚洲一区二区三区视频| 免费亚洲视频| 嫩草国产精品入口| 国模叶桐国产精品一区| 亚洲一区二区三区精品视频| 99精品欧美一区二区三区| 久久久久久网址| 久久久久久午夜| 国产日韩精品一区二区| 一区二区三区 在线观看视| 亚洲人成在线播放| 久久精品99无色码中文字幕 | 久久狠狠亚洲综合| 国产精品国产| aaa亚洲精品一二三区| 亚洲国语精品自产拍在线观看| 欧美在线你懂的| 久久狠狠久久综合桃花| 国产日韩精品入口| 午夜在线一区| 久久精品国产77777蜜臀| 国产精品国产成人国产三级| 亚洲欧洲在线一区| 99在线热播精品免费| 蜜桃av噜噜一区| 欧美一区二区三区的| 激情久久影院| 西西人体一区二区| 欧美一区二区在线| 国产一区二区丝袜高跟鞋图片| 午夜精品视频| 久久一区二区精品| 影音先锋中文字幕一区| 久久久91精品| 亚洲电影免费在线观看| 亚洲欧洲一区二区在线观看| 欧美激情va永久在线播放| 亚洲日韩第九十九页| 亚洲天堂av在线免费观看| 欧美天天综合网| 午夜欧美不卡精品aaaaa| 久久久国产午夜精品| 伊人久久大香线蕉综合热线| 久久综合中文字幕| 亚洲精品永久免费| 亚洲午夜91| 很黄很黄激情成人| 欧美大片在线观看| 一区二区三区视频观看| 久久久久网址| 日韩一级不卡| 国产亚洲欧美日韩一区二区| 免费中文字幕日韩欧美| 一区二区三区欧美在线| 久久综合九色综合久99| 日韩西西人体444www| 国产精品欧美日韩一区| 久久久久久久欧美精品| 99精品久久免费看蜜臀剧情介绍| 久久成人精品视频| 日韩视频免费观看高清在线视频 | 亚洲第一天堂无码专区| 亚洲特色特黄| 亚洲二区在线| 国产精品久久影院| 久久综合九色欧美综合狠狠| 夜夜爽www精品| 欧美va天堂va视频va在线| 亚洲免费小视频| 亚洲激情第一区| 国产亚洲一级高清| 欧美日韩一区二| 裸体歌舞表演一区二区| 亚洲欧美日韩国产综合在线| 91久久国产综合久久| 久久蜜桃香蕉精品一区二区三区| aⅴ色国产欧美| 亚洲人成毛片在线播放女女| 国产亚洲一区二区精品| 欧美特黄一级大片| 欧美大成色www永久网站婷| 欧美在线影院| 亚洲免费网址| 一区二区成人精品| 最新亚洲电影| 欧美高清一区| 欧美国产综合视频| 久久婷婷亚洲|