Template Function Overloading Sample

Description

When you have several functions and function templates, that could potentially be invoked for a function call, a process known as overload resolution is applied to find the right function to invoke. This process has several aspects, which we will describe as part of explaining the sample program:

Concept

The sample program defines four templates, and then issues a series of function calls.

f(s) could match any of f(char*), f(T), or f(T*). Based on [3] above, it exactly matches f(char*).

f(sp) could match either f(T) or f(T*). The latter is more specialized, and is therefore preferred over the former based on [2] above.

f(37) is a better match for f(T) than it is for the other candidate, f<double>(double). The latter requires a conversion from int to double.

Finally, f(12.34) is an exact match for f<double>(double).

Supported
Supported
Supported