what is the use of templates?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does class accomplish data hiding in c++?

657


How did c++ start?

606


What are maps in c++?

502


What do you mean by overhead in c++?

571


What is fflush c++?

574






Which coding certification is best?

566


What is algorithm in c++ programming?

585


A mXn matrix is given and rows and column are sorted as shown below.Write a function that search a desired entered no in the matrix .with minimum complexity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

3237


Is swift a good first language?

586


How would you use the functions memcpy(), memset(), memmove()?

622


Tell me an example where stacks are useful?

590


Differentiate between C and C++.

705


What happens when the extern "c" char func (char*,waste) executes?

632


what is the difference between overloading & overriding? give example.

561


Describe public access specifiers?

577