Ray's playground

 

C++ templates chapter 11(Template Argument Deduction)

  Explicitly specifying template arguments on every call to a function template (for example, concat<std::string, int>(s, 3)) can quickly lead to unwieldy code. Fortunately, a C++ compiler can often automatically determine the intended template arguments using a powerful process called template argument deduction.

  The deduction process compares the types of an argument of a function call with the corresponding parameterized type of a function template and attempts to conclude the correct substitution for one or more of the deduced parameters. Each argument-parameter pair is analyzed independently, and if the conclusions differ in the end, the deduction process fails. Consider the following example:

posted on 2009-10-21 21:38  Ray Z  阅读(248)  评论(0编辑  收藏  举报

导航