what is the use of templates?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is a smart pointer?
What relational operators if statements in c++?
What is the latest version on c++?
What is a reference in C++?
give me an example for testing a program showing the test path .show how the test is important and complex.
Types of storage and scope of each type
Problem 6: Area of a trapezoid can be calculated by the following formula: A=(b1 b2)×h2 where b1 and b2 are the parallel sides or the bases and h is length of height Write a C code of this program
What do you mean by stack unwinding in c++?
Difference between linked list and array?
What is the difference between structures and unions?
the first character in the variable name must be an a) special symbol b) number c) alphabet
When does a name clash occur in c++?