Coupon Accepted Successfully!



The template is one of the most useful characteristics of the C++. A few old compilers do not allow the template mechanism. Templates are a part of ANSI C++ standard. All major compilers support templates in their new versions. Instantiation is the activity of creating a particular type using a template. The specific classes are known as instance 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. A function that works for all C++ data types is called a generic function. Templates help the programmer declare groups of functions or classes. When used with functions, they are called function templates. For example, we can create a template for the function, square(). It helps us calculate the square of a number of any data type, including int, float, long, and double. The templates can be associated with classes; such templates are called class templates. A template is almost similar to a macro, and it is type secured. The difference between a template and a macro is illustrated.

Test Your Skills Now!
Take a Quiz now
Reviewer Name