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

Which one of the following describes characteristics of "protected" inheritance? a) The base class has access only to the public or protected members of the derived class. b) The derived class has non-public, inheritable, access to all but the private members of the base class. c) The derived class has access to all members of the base class. d) The private members of the base class are visible within the derived class. e) Public members of the derived class are privately accessible from the base class.

4 Answers   Quark,


Why c++ is created?

0 Answers  


If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?

0 Answers  


What is the difference between structures and unions?

0 Answers  


Which operations are permitted on pointers?

0 Answers  






What is the fastest c++ compiler?

0 Answers  


How can an improvement in the quality of software be done by try/catch/throw?

0 Answers  


What is a reference in C++?

1 Answers  


How do I get good at c++ programming?

0 Answers  


What is a literal in c++?

0 Answers  


Where Malloc(), Calloc(), and realloc() does get memory?

0 Answers  


Write a program to concatenate two strings.

0 Answers  


Categories