2.3 Template Parameters
Outlier (强迫症真闹心)
- 章节名:2.3 Template Parameters
So far, we have looked at cases in which either all or none of the function template arguments were mentioned explicitly. Another approach is to specify only the first arguments explicitly and to allow the deduction process to derive the rest. In general, you must specify all the argument types up to the last argument type that cannot be determined implicitly. Thus, if you change the order of the template parameters in our example, the caller needs to specify only the return type:
template <typename RT, typename T1, typename T2> inline RT max (T1 const& a, T2 const& b); … max<double>(4,4.2) // OK: return type is doubleIn this example, the call to max<double> explicitly sets RT to double, but the parameters T1 and T2 are deduced to be int and double from the arguments.
Outlier对本书的所有笔记 · · · · · ·
-
2.1.2 Using the Template
Thus, templates are compiled twice: Without instantiation, the template code itself is ...
-
2.2 Argument Deduction
Cast the arguments so that they both match: max(static_cast
(4),4.2) // OK Sp... -
2.3 Template Parameters
说明 · · · · · ·
表示其中内容是对原文的摘抄