What are templates?

Templates is a feature of the C++ programming language that allows functions and classes to deal with generic types. This allows a function or class to handle a wide range of data types without having to rebuild it.

Here is a simple function template to add two numbers of any type.

Get hands-on with 1200+ tech skills courses.