September 2017
Intermediate to advanced
822 pages
26h 51m
English
Function overloading allows the same function name to be used for multiple functions, so long as those functions are distinguished by their parameter types. For example:
void f (int); void f (char const*);
With function templates, one overloads on type patterns such as pointer-to-T or Array<T>:
template<typename T> void f(T*); template<typename T> void f(Array<T>);
Given the prevalence of type traits (discussed in Chapter 19), it is natural to want to overload function templates based on the properties of the template arguments. For example:
template<typename Number> void f(Number); // only for numbers template<typename Container> void f(Container); ...
Read now
Unlock full access