answersLogoWhite

0


Best Answer

Template functions provide the ability to write a single function that can accept different types of inputs and produce different types of output, while still using the same logic. For example, a template function can accept an int, long, or float and perform the same logic on any of the three types of parameters. The compiler ensures that the template function will make sense when compiled with a particular type. This was an early attempt at polymorphism (using the same code on different types of objects), and has since been superseded in newer languages using objects and inheritance.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the purpose of template functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How you describe operations of stack ADT using c template functions?

No, because C does not support the concept of template functions. Template functions only exist in C++, never in C.


What is the differnce between ordinary function and template function of c language?

The c language does not have template functions. That is a c++ thing.


How will you overload a template function?

The only reason to overload a template function is to provide an overload that differs in the number and type of arguments that cannot be addressed by the template function alone. You simply declare them as you would any other overload. The overloads may themselves be template functions, but there must be no ambiguity: every template function must generate an unique function signature. Remember that template functions generate overloads at compile time on an as-required basis.


What are the functions of frame relay?

networking purpose


When will you create a template function in c plus plus?

You will create a template function whenever you have a function implementation that can be overloaded to cater for more than one type. Rather than re-write the same implementations over and over to cater for each type you might use now or in the future, you template the type and write one version of the function. The compiler will then generate all the necessary overloads for you on an as-required basis. This helps reduce maintenance when you need to alter the implementation because the code is all in one place, so there is no need to duplicate your changes by hand, which is both time-consuming and prone to error. Template functions are intended as an alternative to macro functions. While macros do have their uses, particularly in debug code, they are not type safe and cannot be debugged. Moreover, macros are always inline expanded whereas template functions are only inline expanded when the compiler's optimisers determine that there is an advantage in doing so.

Related questions

How you describe operations of stack ADT using c template functions?

No, because C does not support the concept of template functions. Template functions only exist in C++, never in C.


What is the differnce between ordinary function and template function of c language?

The c language does not have template functions. That is a c++ thing.


How will you overload a template function?

The only reason to overload a template function is to provide an overload that differs in the number and type of arguments that cannot be addressed by the template function alone. You simply declare them as you would any other overload. The overloads may themselves be template functions, but there must be no ambiguity: every template function must generate an unique function signature. Remember that template functions generate overloads at compile time on an as-required basis.


What is a pre formatted database design for a specific purpose?

template


What functions as the template during translation?

messenger RNA


What is difference between template and inline functions?

Template function would be global, they would have effect on all the pages within the template. Inline, would be regarding a specific line of code within a table or Div tag.


What is a business proposal template?

A business proposal template is the basic outlining of the purpose and practice of the specific business it is for. A template is generally open for multiple ideas and different businesses to use. A guideline that allows for a flow of the business model.


What is a partially completed workbook that you can use to create other workbooks that have the same structure and purpose?

template


What is a geometry template?

A geometry template is a piece of clear plastic with cut-out shapes for use in mathematics and other subjects in primary school through secondary school. It functions as a stencil, protractor, ruler, and straightedge.Source: WikiPedia


What are the functions frame relay?

networking purpose


What are the functions of frame relay?

networking purpose


What are the functions of general assembly?

they don't have a true purpose.