I’m creating a little application and needs to use Template Functions. Pretty much it is supposed ask the user to enter 2 of some data type and then tell them which one of the two is greater. So as a template function I want to tell what is being passed to my function. For example, if the function takes doubles I want to be able to ask the user “Enter 2 Doubles.” and so forth. This is the function call and set up:
int main(){
getInput(intA, intB);
getInput(doubleA, doubleB);
...
}
template <typename TYPE>
TYPE getInput(TYPE a, TYPE b){
cout << "Enter 2 " << TYPE << endl;
cin >> a >> b;
...
}
This application is a work in progress but it just bugs me asking the user to “Enter Some Input” etc. Not even sure if this is possible but thought it would be cool.
Use RTTI: