Home | | Programming and Data Structure II | Parameterizing the Classes

Chapter: Programming and Data structures : C++ Programming Advanced Features

Parameterizing the Classes

A template can be used as a family of classes or functions. It can be considered as a macro. When an object of a specific type is defined for actual use, the template definition for that class is substituted with the required data type.

PARAMETERIZING THE CLASSES:

 

A template can be used as a family of classes or functions. It can be considered as a macro. When an object of a specific type is defined for actual use, the template definition for that class is substituted with the required data type. Since a template is defined with a parameter that would be replaced by a specified data type at the time of actual use of the class or function, the templates are sometimes called parameterized classes or functions.

 

We can use more than one generic data type in a class template. They are declared as a comma separated list within the template specification.

 

Syntax:

 

template<class T1, class T2,…..> class classname

 

{

 

…….

 

…..

 

(Body of the class)

 

……

 

};

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Programming and Data structures : C++ Programming Advanced Features : Parameterizing the Classes |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.