Monday, April 20, 2009

TEMPLATE

Introduction

We can define templates for both classes and functions. A template can be used to create a family of classes or functions. For example, a class template for an array class would enable us to create arrays of various data types such as linearly and float array. Similarly, we can define a template for a function, say mul(). That would help us create various versions of mul() for multiplying int, float and double type values.
A template can be considered as a king of 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 the specified data type at the time of actual use of the class or function, the templates are sometimes called parameterized classes or function.
Click here

No comments:

Post a Comment