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

Can I run c program in turbo c++?

0 Answers  


How to stop conversions among objects?

5 Answers   Symphony,


What will happen if I allocate memory using "new" and free it using "free" or allocate sing "calloc" and free it using "delete"?

3 Answers  


string somestring ; Which of the following choices will convert a standard C++ string object "somestring" to a C string? a) Copy.somestring () ; b) somestring.c_str () c) &somestring [1] d) std::cstring (somestring) e) (char *) somestring

1 Answers   Quark,


What do you mean by inheritance in c++? Explain its types.

0 Answers  






List the issue that the auto_ptr object handles?

0 Answers  


What are virtual functions in c++?

0 Answers  


Why is c++ considered difficult?

0 Answers  


What is the importance of mutable keyword?

0 Answers  


please help to write the code of chess game in c++??????????

1 Answers   NEC,


What is the use of turbo c++?

0 Answers  


What is the need of a destructor?

0 Answers  


Categories