#include <iostream>
using namespace std;
template <class T>
class addition
{
private:
T num1, num2;
public:
addition(T n1, T n2)
{
num1 = n1;
num2 = n2;
}
void data()
{
cout << "Numbers are: " << num1 << " and " << num2 << "." << endl;
cout << "Addition is: " << add() << endl;
}
T add()
{
return num1 + num2;
}
};
int main()
{
addition<int> intCalc(8, 2);
addition<float> floatCalc(3.7, 7.3);
cout << "Int results:" << endl;
intCalc.data();
cout << endl << "Float results:" << endl;
floatCalc.data();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: