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... (查看原文)
0 有用 hurricane 2011-06-12 14:50:47
可以大致看看就去看modern c++ design,太多的特性,还没有compiler支持,看太多也木有用。
0 有用 Lucadna 2013-04-03 15:05:17
不看这本别说会用template
0 有用 晨星 2010-05-03 13:58:26
书本身不错,模板的方方面面,从语法到应用都涉及了。 就是觉得对大多数人而言,收益投入比太低,但比元编程那本还好一点。
0 有用 Lucadna 2013-04-03 15:05:17
不看这本别说会用template
0 有用 hurricane 2011-06-12 14:50:47
可以大致看看就去看modern c++ design,太多的特性,还没有compiler支持,看太多也木有用。
0 有用 晨星 2010-05-03 13:58:26
书本身不错,模板的方方面面,从语法到应用都涉及了。 就是觉得对大多数人而言,收益投入比太低,但比元编程那本还好一点。