In programming, we often use the same function as the function body, if we want to decide which function to invoke depending on the parameter table we use, we often use the function overloading, but when we have a lot of functions we find it inconvenient to implement. So C + + provides the concept of a function template, which is similar to the way a class template is implemented.
For example, we often want to use the bubbling sorting algorithm, the object being sorted may be double,int,char,float, and so on, here is the implementation code:
Template <typename t1,typename t2>void bubble (T1 *a, T2 len) {T1 temp;for (int i=0;i<len;i++) {for (int j=i;j< len;j++) {if (A[i]>a[j]) {temp=a[i]; A[I]=A[J]; a[j]=temp;}}}}This allows us to make a specific function call based on the type of object being sorted.
Use of function templates in C + +