Template function is a type of function which only describes the procedure or statements of the function, i.e. what the function will do, but do not specify the data type of arguments. Thus a template class is a basic skeleton.
T swap(T &a, T &b)
temp = a;
a = b;
b = temp;
int main (int argc, char *argv)
int i = 10, j = 20;
cout << "Values i, j " << i << ", " << j;
float a = 3.14, b = -6.28;
cout << "Values a, b " << a << ", " << b;
From the above code, it is clear that if template was not used then individual functions have to be used to carry out swap of every data type used.
Considering a class queue which adds elements to the rear and removes element from the front of an array.
const int MAX = 10;
private: T que[MAX];
You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.