The compiler refuses the following code to me trying to assign num1 and num2 to different types at once.
#include <iostream>
using namespace std;
template <class T1, class T2> //at most user can compare 2 different types
//T maximum(T1, T2);
//T minimum(T1, T2);
void maximum(T1 & n1, T2 & n2)
{
cout << ( n1 > n2 ? n1 : n2 ) << " is greater." << endl;
}
//void minimum (T1 n1, T2 n2)
int main()
{
//T1 num1;
//T2 num2;
int num1;
double num1;
int num2;
double num2;
char num1;
char num2;
string num1;
string num2;
cout << "Enter a number: ";
cin >> num1;
cout << endl;
cout << "Enter a 2nd number: " << endl;
cin >> num2;
cout << endl;
maximum(num1, num2);
system("pause");
return 0 ;
}

New Topic/Question
Reply



MultiQuote



|