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

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

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

 

"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国产一区二区三精品乱码| 艳女tv在线观看国产一区| 亚洲欧美日本精品| 久久久精品tv| 欧美高清视频在线| 国产精品区一区二区三| 国产一区二区三区视频在线观看| 在线观看91精品国产麻豆| 久久成人18免费观看| 久久亚洲色图| 欧美精品国产精品日韩精品| 国产精品日韩一区二区| 亚洲成人自拍视频| 一区二区三区国产精品| 久久综合九色| 一区二区激情视频| 久久综合九色综合欧美狠狠| 欧美日韩在线一区二区| 尹人成人综合网| 亚洲在线1234| 亚洲狠狠丁香婷婷综合久久久| 亚洲永久免费观看| 欧美美女bbbb| 狠狠色2019综合网| 亚洲欧美色一区| 亚洲二区在线视频| 久久国产一区二区| 欧美视频网址| 亚洲欧洲一区二区三区| 久久精品国产一区二区电影| 亚洲精品美女免费| 久久女同互慰一区二区三区| 国产精品国产成人国产三级| 亚洲精品视频免费在线观看| 久久久久久久久久久久久女国产乱 | 一区二区三区在线免费视频| 亚洲天堂第二页| 欧美国产日韩一区二区在线观看| 亚洲摸下面视频| 欧美性猛交视频| 日韩一区二区精品在线观看| 亚洲第一在线综合在线| 久久亚洲精品中文字幕冲田杏梨| 国产精品视频免费一区| 亚洲午夜免费福利视频| 亚洲剧情一区二区| 欧美精品粉嫩高潮一区二区| 亚洲精品乱码久久久久久蜜桃91| 麻豆精品精品国产自在97香蕉| 欧美一区永久视频免费观看| 国产欧美日本在线| 欧美一区二区三区视频| 亚洲校园激情| 国产美女精品| 久久国内精品视频| 欧美一区免费| 一区二区三区亚洲| 欧美承认网站| 美女日韩在线中文字幕| 91久久极品少妇xxxxⅹ软件| 亚洲丁香婷深爱综合| 欧美日韩视频在线一区二区 | 亚洲欧美久久久久一区二区三区| 亚洲级视频在线观看免费1级| 欧美大片第1页| 一本色道久久综合亚洲精品按摩 | 亚洲黄网站在线观看| 欧美激情国产精品| 亚洲精品日韩欧美| aa国产精品| 国产婷婷色一区二区三区四区| 久久综合九色九九| 欧美成人免费全部| 亚洲免费视频一区二区| 午夜日韩激情| 亚洲第一福利社区| 亚洲毛片在线看| 国产一二三精品| 亚洲人成在线观看| 国产精品三级视频| 免费久久99精品国产自| 欧美日韩人人澡狠狠躁视频| 久久精品国产2020观看福利| 欧美成人精品高清在线播放| 亚洲小说春色综合另类电影| 久久精品人人做人人综合| 欧美成年人在线观看| 亚洲欧美美女| 欧美暴力喷水在线| 欧美一级日韩一级| 欧美成人亚洲成人日韩成人| 香蕉国产精品偷在线观看不卡| 久久在线视频| 午夜日韩视频| 欧美精品日韩一本| 久久婷婷激情| 国产精品捆绑调教| 亚洲国产精品久久| 国产一区二区三区黄视频| 亚洲三级视频| 亚洲国产成人精品视频| 午夜在线a亚洲v天堂网2018| 一区二区三区高清不卡| 久久综合久久久| 久久成人免费网| 欧美日韩中文字幕日韩欧美| 久久亚洲不卡| 国产欧美日韩91| 夜夜嗨av一区二区三区四区| 亚洲级视频在线观看免费1级| 性色av一区二区三区红粉影视| 亚洲午夜精品久久| 欧美国产丝袜视频| 欧美大片在线观看| 尤物九九久久国产精品的分类| 亚洲欧美欧美一区二区三区| 99热免费精品在线观看| 免费精品99久久国产综合精品| 久久久久一区| 国产一区二区丝袜高跟鞋图片 | 欧美不卡视频一区| 国产一区二区三区在线观看视频| 亚洲一区二区不卡免费| 亚洲午夜精品一区二区| 欧美日韩国产在线播放网站| 最近中文字幕日韩精品| 最新中文字幕一区二区三区| 久久久久9999亚洲精品| 久久夜色精品国产噜噜av| 国产亚洲综合在线| 久久精品视频亚洲| 久久嫩草精品久久久精品| 黄色日韩精品| 噜噜噜91成人网| 亚洲国产美女精品久久久久∴| 亚洲国产精品久久久久久女王| 久热精品在线| 欧美岛国激情| 日韩一级精品| 国产精品毛片va一区二区三区| 亚洲一卡久久| 久久精品国产999大香线蕉| 国内欧美视频一区二区| 久久久久综合网| 亚洲高清在线精品| 亚洲一区二区三区777| 国产日产欧美a一级在线| 性欧美暴力猛交69hd| 欧美成人精品一区二区| 在线视频亚洲| 国产一区欧美| 欧美激情影音先锋| 亚洲天堂网在线观看| 久久夜色精品一区| 亚洲欧洲一区二区天堂久久| 欧美日韩国产丝袜另类| 亚洲欧美综合另类中字| 亚洲大片一区二区三区| 亚洲性夜色噜噜噜7777| 国产三级欧美三级| 欧美大片网址| 亚洲欧美综合精品久久成人| 欧美 亚欧 日韩视频在线| 一区二区免费在线播放| 国产视频一区二区在线观看 | 99成人在线| 国产欧美精品国产国产专区| 久久综合伊人77777蜜臀| 99视频精品在线| 久久精品盗摄| 日韩视频免费观看高清完整版| 国产精品视频一区二区三区| 久久免费国产精品| 亚洲午夜久久久久久久久电影院| 免费成人毛片| 久久av资源网站| 99精品免费网| 在线成人国产| 国产一区二区三区网站| 欧美日韩亚洲天堂| 美女主播一区| 欧美在线观看一区二区| 亚洲精品一区二区三区99| 久久亚洲欧洲| 欧美一级一区| 亚洲一区图片| 99re这里只有精品6| 亚洲福利视频一区| 猫咪成人在线观看|