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 is Virtual Inheritance?

7 Answers   Amazon, Wipro,


What is the purpose of the noexcept keyword?

1 Answers  


Tell me an example where stacks are useful?

1 Answers  


What is class in c++ with example?

1 Answers  


What does ctime() do?

1 Answers  


How the keyword struct is different from the keyword class in c++?

1 Answers  


What is implicit conversion/coercion in c++?

2 Answers  


declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator

1 Answers  


What is object slicing and how can we prevent it?

2 Answers   Tech Mahindra,


What is an explicit constructor?

1 Answers  


Can circle be called an ellipse?

1 Answers  


What is a multimap c++?

1 Answers  


Categories