Overloading can be really tedious. Imagine you want to create a new function that works with int, float, double, and other number types. Do you really need to redefine the SAME function body over and over again with different parameters?

Thankfully not! When two functions have different types but the same body — as was the case with print_cat_ears() —, there is a cleaner solution you can use: templates.

A template is a C++ tool that allows programmers to add data types as parameters.

This feature comes in handy for classes as well as for functions. In fact, std::string and std::vector are both template-based types. The C++ standard library is full of templates!


Take a look at how function templates allow you to use less code to make more than one function.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?