A template is one of the most useful characteristics of C++. It is newly added in C++. Instantiation is the activity of creating a particular type using a template. The specific classes are known as instances of the template. The template provides generic programming by defining generic classes. In templates, generic data types are used as arguments, and they can handle a variety of data types.
The declaration and definition of every template class starts with the keyword template followed by the parameter list.
The class template may contain one or more parameters of generic data type. The arguments are separated by commas with a template declaration.
Function templates can be defined with one or more parameters.
A template function also supports the overloading mechanism. It can be overloaded by a normal function or a template function.
It is also possible to define member functions outside the class. While defining them outside, the template function should define the function, and the template classes are parameterized by the type argument.
Test Your Skills
Test Your Skills Now!
This is only a practice test, it is designed to help you revise your concepts
The test contains questions, only 1 option is correct for each question
This is a timed test.
After you have finished the test, press on the 'Finish Test' button to know your score and get the correct answers