Friday, January 17, 2014

template argument deduction c++

template argument deduction c++ : templates tutorial ccplusplus.com
When we call a function template such as max() for some arguments, the template parameters are determined by the arguments we pass. If we pass two ints to the parameter types T const&, the C++ compiler must conclude that T must be int. Note that no automatic type conversion is allowed here. Each T must match exactly. For example:


There are three ways to handle such an error:
  1. Cast the arguments so that they both match:

  2. Specify (or qualify) explicitly the type of T:

  3. Specify that the parameters may have different types.

For a detailed discussion of these topics, see the next section.

No comments:

Post a Comment