A C++ pointer variable that stores the address of a function is called a function pointer. Can we create a function pointer to a function template also, or are function pointers only limited to non-template functions? The answer is that we can create a function pointer to an instance of a function template. Strictly speaking, a function template itself is not a function but a template to many possible function instances.
Let's look at one function template:
template<typename From, typename To>
To Convert(const From& f) {
return To(f);
}
Convert can be instantiated and called as:
std::cout << Convert<double,int>(10.5) << "\n"; // prints 10
std::cout << Convert<int,char>(65) << "\n"; // prints A
Suppose we want to create a function pointer fPtr to Convert< double, int >, which is an instance of Convert, so we can invoke fPtr like this:
std::cout << fPtr(10.5) << "\n"; // prints 10
Select all the correct definitions of fPtr from below: