what is the use of templates?

Answers were Sorted based on User's Feedback



what is the use of templates?..

Answer / aboelella

Template is used to optimize code
instead of implementing the same code for multiple data
types, template works as a way to declare classes and
functions and then to be implemented with different data types

It is dependent on the data structure used to substitute the
template

Is This Answer Correct ?    18 Yes 0 No

what is the use of templates?..

Answer / achal

In C++ there are 2 kinds of templates. i) function
templates ii) Class templates.
Among these class templates are more common.
e.g.
template <class T > class Sample
{
public:
T m1;
void fun(T);
};
Now here we have created a class which has a data member of
type T. Now this T can be int, unsigned int, char etc.
Thus templates are said to be used for generic programming.

Is This Answer Correct ?    1 Yes 0 No

what is the use of templates?..

Answer /

templates are used for GENERIC.....Programing...

by using templates.....you can write program for generic
linked list .

tempaltes make code reusable....

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C++ General Interview Questions

State the difference between delete and delete[].

0 Answers  


Differentiate between structure and class in c++.

0 Answers  


Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find out the 10th last node/item in a linked list.

16 Answers   BNB, FDS, Goldman Sachs, Nagarro,


What are the advantages of using friend classes?

0 Answers  


Explain differences between alloc() and free()?

0 Answers  






Describe exception handling concept with an example?

0 Answers  


When there is a global variable and local variable with the same name, how will you access the global variable?

0 Answers  


Which programming language is best to learn first?

0 Answers  


Consider the following code fragment: int main(void) { int m = 4; mystery ( m ); mystery ( m ); printf("%d", m); return 0; } What is the output on the monitor if mystery is defined as follows ? void mystery (int m) { m = m+3; }

2 Answers   CDAC, Wipro,


What is the benefit of learning c++?

0 Answers  


Describe new operator and delete operator?

0 Answers  


1.Between 100 and 999 are some numbers that have the characteristics that if you cube the individual digits and sum together you will get the same number. 2. A program that can accept as input an integer and output the equivalent of that number in words.

3 Answers  


Categories