I'm writing an example program to help build an understanding of templates in C++. I am trying to use a template class to have more than one functionality.
Below is the following code I have written up.
// Example program
#include <iostream>
#include <string>
using namespace std;
template<class test>
test addstuff(test a, test b){
return a+b;
}
test multiplystuff(test a,test b){
return a*b;
}
int main()
{
double a,b,c;
cout << "Enter a value for a." << endl;
cin >> a;
cout << "Enter a value for a." << endl;
cin >> b;
c = addstuff(a,b);
cout << c << endl;
c = multiplystuff(a,b);
cout << c << endl;
}
The error I am getting is in the test multiplystuff
in my function, it is not within scope is the error I receive. I expect the template to be able to handle more than one functionality, What could the problem be?