AIM: Write a c++ program to illustrate templates with multiple parameters.
THEORY:
While creating templates, it is possible to specify more than one type. We can use more than one generic data type in a class template. They are declared as a comma-separated list within the template as below:
Syntax:
template<class T1, class T2, …>
class classname
{
…
…
};
SOURCE COE:
#include<iostream>
using namespace std;
template<class T1,class T2>
class data
{
public:
data(T1 a,T2 b)
{
cout<<“a= “<<a<<“\nb= “<<b<<endl;
}
};
int main()
{
data<int,float>h(2,2.5f);
data<int,char>i(15,’M’);
data<float,int>j(3.12f,50);
}
OUTPUT:
a= 2
b= 2.5
a= 15
b= M
a= 3.12
b= 50