#include <iostream>
using namespace std;
//declaration of generic class
template <class T> class addition
{
public:
//generic function
void add(T a,T b)
{
T ans;
ans=a+b;
cout<<"Addition of "<<a<<" and
"<<b<<" is "<<ans<<endl;
}
};
int main()
{
//declaring class that receives integer data
addition<int> obj;
//declaring class that receives float data
addition<float> obj2;
obj.add(10,20);//class receives integer data as input and outputs
integer value as answer
obj2.add(15.5,10.2);//same class here receives float data as input
and output float value as answer
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.