C++ supports a mechanism known as template to implement the concept of generic programming .
Templates allows us to generate a family of classes or a family of functions to handle different types.
Template classes and functions eliminate code duplication for different types and thus make the program development easier and more manageable.
We can use multiple parameters in both the class templates and function templates.
A specific class created from a class template is called a template class and the process of creating a template class is known as instantiation. Similarly, a specific function created from a function template is called a template function.
Like other functions, template functions can be overloaded.
Member functions of a class template must be defined as function templates using the parameters of the class template.
We may also use non - type parameters such basic or derived data types as arguments templates.
No comments:
Post a Comment