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

What do you mean by const correctness?

717


Is map ordered c++?

688


What is the full form nasa?

673


Why do we need runtime polymorphism in c++?

646


What is constructor and destructor in c++?

707






Explain how to initialize a const data member.

704


Eplain extern keyword?

664


What is the difference between while and do while loop? Explain with examples.

688


How does java differ from c and c++?

621


what are the iterator and generic algorithms.

1560


What are iterators in c++?

683


Why the usage of pointers in C++ is not recommended ?

984


Explain the extern storage classes in c++.

646


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create

2156


Explain static and dynamic memory allocation with an example each.

728