And please could it be in english . I gotta hear it in plain english before I can understand it in geekspeak .
-CDuddley
And please could it be in english . I gotta hear it in plain english before I can understand it in geekspeak .
-CDuddley
A class or function capable of recieving/containing different types without needing to overload for each case.
They act as templates.
zen
A template enables you to write code that generalizes data types. For example, if you want a swap function for chars, it would be like this
void swap(char& a, char& b) {
char temp = a;
a = b;
b = temp;
}
But then, if you wanted to use a swap function for doubles, you would have to write another swap function
void swap(double& a, double& b) {
double temp = a;
a = b;
b = temp;
}
Then, you'd need another for int, and float, and any class/struct you've created on your own, so you could generalize this into a template.
template <class T> //every instance of T will be replaces by the data type
void swap(T& a, T& b) {
T temp = a;
a = b;
b = temp;
}