answersLogoWhite

0

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.

User Avatar

Wiki User

11y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

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 do you create folder with c plus plus?

Use function mkdir.


What has the author Mark Nelson written?

Mark Nelson has written: 'C++ programmer's guide to the standard template library' -- subject(s): C++ (Computer program language), Standard template library, C. 'C [plus plus] programmer's guide to the Standard Template Library' -- subject(s): C.


When and how a c compiler generate actual function from its template?

At the point it is used.


What are the building function in c plus plus?

There is no such term as "building function" in C++.


How to write C plus plus Program to take 2 distant values as argument and return the larger value on the screen?

Use the following template function: template<class T> T& max(T& x, T& y){return(y<x?x:y;}


Where is the function declare in c plus plus language?

All function interfaces must be declared before they can be used. This is known as a forward declaration and is strictly enforced in C++ (but not in C). To facilitate this, interfaces are typically placed in a header file which can then be included in every source file that requires access to that function. The interface need not be defined (implemented) in the header unless the function is a template function. Typically, implementations are kept separate from interfaces (template function implementations are kept in the header but typically separated from the interface) since the interface contains everything the user needs to know in order to make use of the function.


What is message passing in c plus plus?

-define class with necessary data member & member function. -create object of that class. -communication.


What is default name of c plus plus?

If you mean the original name of C++, it was originally called "C with Classes". However, after the introduction of template metaprogramming, it was renamed C++ which meant "the successor to C".


A c plus plus statement that invokes a function is known as?

...a function call.


How do you create .exe file in c plus plus?

You can create an exe-file from your C++ source, if you have a compiler.


How do you create functions with multiple parameters in C plus plus?

Random example, function with two parameters: int main (int argc, char **argv) {...}