Self-explanatory see the example
template<typename T> const T &min(T const &x, T const &y)
{
return (x < y ? x : y);
}
min(2,3) // return 3 Implicit instanciation
max<std::string>("str1","str2") // return str2 Explicit instanciation
template<typename T> class randomClasse
{
randomClasse<T>(void);
~randomClasse<T>(void);
...
}
template<typename T = int> class randomClasse // default type is integer
{...}
template<typename T> ostream & operator<<(...) // operator overloads have to be templates as well
Variante d'un template qui peut être partielle ou complète
template<typename T, typename U> class randomClass
{...}
template<typename U> // Partial
class randomClass<int, U> {...}
template<>
class randomClass<bool, bool> {...} // Full
kind of templates in c Pas ouf, limites vite atteintes
#define max(x,y) (((x)==(y)) > (x) : (y))