Function templates are functions that are parameterized so that they represent a family of functions; it means that we can have the same functional behavior for different data types.
They start with the keyword "template" template template inline T const& max(T const& a, T const& b) { return a <> The process of replacing template parameters by concrete types is called "instantiation", and mere use of a function template will trigger instantiation; it means that we don't have to instantiate it manually. Templates are compiled twice:- Without instantiation
- At the time of instantiation (Can break the regular rules of compile/link)
- Template parameters T, one type of template parameters are "type parameters" that are declared using "typename" keyword
- Call parameters
inline int const& max (int const& a, int const& b) { return a <> inline T const& max(T const& a, T const& b) { return a <> inline T const& max(T const& a, T const& b, T const& c) { return ::max (::max(a, b), c); }
No comments:
Post a Comment