Thus, templates are compiled twice:
Without instantiation, the template code itself is checked for correct syntax. Syntax errors are discovered, such as missing semicolons.
At the time of instantiation, the template code is checked to ensure that all calls are valid. Invalid calls are discovered, such as unsupported function calls.
This leads to an important problem in the handling of templates in practice: When a function template is used in a way that triggers its instantiation, a compiler will (at some point) need to see that template's definition. This breaks the usual compile and link distinction for ordinary functions, when the declaration of a function is sufficient to compile its use. Methods of handling this problem are discussed in Chapter 6. For the moment, let's take the sim... (查看原文)
01 学习C++模板技术的经典之作 C++ 技术爱好者们,特大喜讯来啦!《C++ Templates(第2版)中文版》将要上市,第 2 版相距第 1 版已有15年,这一次更新可以说是全面拥抱了现代 C++ 的语言特性。 C++ 程序员都知道,模板技术是一种强大的特性,可以让程序员编写尽可能通用的代码...
(展开)
0 有用 lyx2007825 2017-09-18 12:07:36
模板可以读这本书入门,囊括的东西还是蛮多的
0 有用 halo 2009-05-12 16:35:45
电子版,杂
0 有用 赵映 2019-03-31 15:57:12
看的中文版,很丰富。但涉及到元编程的不多
0 有用 懂懂 2009-02-09 09:49:30
细节巨多,看着有点头大,但是后几章非常赞。欲深究C++者必读
0 有用 小K 2012-05-19 21:33:13
强大的模板,好吧,我只想读懂stl、boost的源码而已