tamplate
C++ supports two types of templates: class templates and function templates.
First, let me introduce function templates. When coding, if you need to call the same function for different variable types, using a template should be the best solution. In the template, we use a virtual type to specify the function. Before we specify the templates, we must make a declare:
template <typename T1, typename T2, ...>
Here is an example:
Result:
Next, let's look into the class templates. Like function templates, a declaration is also needed before we specify the class. The declaration is the same as function templates:
template<typename T1, typename T2, ...>
Example:
Result:
Useful link: http://c.biancheng.net/cpp/biancheng/cpp/rumen_14/