answersLogoWhite

0

Templates encourage generic programming. When classes or functions only differ by type, there is no need to write the same implementations over and over -- the compiler generates the functions or classes from the template. You can also cater for specialisation, so if you need a more specific implementation for pointers to types rather than actual types, you can provide the code to cater for this, without the need to duplicate already existing code that caters for all types.

User Avatar

Wiki User

10y ago

What else can I help you with?

Continue Learning about Engineering

How do you add a template to your HTML website in Notepad plus plus?

You can add a template to your HTML website in Notepad plus plus by adding a zen coding plugin in the notepad plus plus.


Which mobile company code is plus plus 372?

Its code of estonia


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.


What is a delegate in C plus plus?

C++ does not have built-in support for delegates, however it is possible to simulate delegation through the use of template hacks. See related links below for more information.


Are there any STL headers which are not part of the C plus plus Standard Library?

The Standard Library includes the Standard Template Library (STL). Therefore no, there are no STL headers that are not part of the Standard Library.

Related Questions

How do you add a template to your HTML website in Notepad plus plus?

You can add a template to your HTML website in Notepad plus plus by adding a zen coding plugin in the notepad plus plus.


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.


Plus 621 is for which country code?

plus 621 what country code


Which mobile company code is plus plus 372?

Its code of estonia


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.


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;}


What is the c plus plus standard template library package you call to use the console for input and output?

The Standard Template Library does not provide routines or packages for I/O. You are probably thinking iostreams library, using cin and cout, which is part of the RunTime Library, but not part of the STL.


What is reading plus site code?

A "site code" for reading plus is a code usually given to you by your teacher. Everyone in your school uses this code. You will have to use this the first time you sign in on reading plus.


What is STL in c plus plus?

Standard Template Library. The STL basically provides templates for common containers, such as lists and queues, as well as functions, iterators and algorithms.


What is plus 324 country code?

Code for Dubai


Is C plus plus preprocessor software?

Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.


C plus plus code for payroll processing?

yihuy