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 is the purpose of the "delete" operator?

628


What is abstraction in c++ with example?

566


Which is best ide for c++?

572


List the issue that the auto_ptr object handles?

616


What is ctime c++?

582






What are the advantages of using pointers in a program?

686


What is polymorphism and its type in c++?

597


How can I learn dev c++ programming?

573


Explain how a pointer to function can be declared in C++?

584


What is difference between c++ and c ++ 14?

583


Difference between a homogeneous and a heterogeneous container

667


What are the manipulators in c++?

555


Name four predefined macros.

599


Explain polymorphism?

586


What are friend classes? What are advantages of using friend classes?

613