Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Templates allow you to write generic code that works with any data type. They are the backbone of the Standard Template Library (STL).
template <typename T>
T getMax(T a, T b) {
return (a > b) ? a : b;
}T is a placeholder for any type (int, double, string, etc.).
Don't Repeat Yourself. One template replaces dozens of overloaded functions.
The compiler generates a specific version of the code for each type used. Zero runtime overhead.