TEMPLATES IN C++
Template is a method of writing a single function or class for a family of similar functions or classes in a generic manner.
template's are used to store value's of all data types in a single variable.
function template:-
when a single function is written for a family of similar functions, it is called a function template. in this function atleast one formal argument is generic.
syntax
template<class T> T function_name(T list of arguments)
{
list of statements;
return(T);
}
function template must start with "template" and T is a parameterized data type.
template's are used to store value's of all data types in a single variable.
function template:-
when a single function is written for a family of similar functions, it is called a function template. in this function atleast one formal argument is generic.
syntax
template<class T> T function_name(T list of arguments)
{
list of statements;
return(T);
}
function template must start with "template" and T is a parameterized data type.
class template:-
A class template is a class definition that describes a family of related classes.
c++ allows the user to create a class that contains one or more data types that are generic or parameterised.
syntax
template<class T>
class class_name
{
private:
T variable_name;
};
A class template is a class definition that describes a family of related classes.
c++ allows the user to create a class that contains one or more data types that are generic or parameterised.
syntax
template<class T>
class class_name
{
private:
T variable_name;
};