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

What are the two types of comments?

0 Answers  


Explain deep copy and a shallow copy?

0 Answers  


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

3 Answers  


What are different types of typecasting supported by C++

1 Answers   CA,


difference between the c++ and c languages

4 Answers   Wipro,






What is the syntax for a for loop?

0 Answers  


What information can an exception contain?

0 Answers  


What are enumerations?

0 Answers  


Explain virtual destructor?

0 Answers  


What is setw manipulator in c++?

0 Answers  


Can we generate a C++ source code from the binary file?

2 Answers  


Differentiate between structure and class in c++.

0 Answers  


Categories