16.2.4. Function Pointers and Argument Deduction
When we initialize or assign a function pointer (§ 6.7, p. 247) from a function template, the compiler uses the type of the pointer to deduce the template argument(s).
As an example, assume we have a function pointer that points to a function returning an int
that takes two parameters, each of which is a reference to a const int
. We can use that pointer to point to an instantiation of compare
:
template <typename T> int compare(const T&, const T&);// pf1 points to the instantiation int compare(const int&, const int&)int (*pf1)(const int&, const int&) = compare;
The type of the parameters in pf1 ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.