Reading values from templates
Mar 14, 2013 at 3:46pm UTC
After asking the user to input 2 values i expect my program to read them and then output whether they are equal, bigger or smaller than one another. However i am getting no output what so ever when i input the values
code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
using namespace std;
int intInput1, intInput2;
float floatInput1, floatInput2;
int x, n;
template <class T>
class Number
{
public :
Number<T>::Number()
{
int x = 0;
}
void Set(int *x)
{
value = x;
}
int Get()
{
return value;
}
private :
int value;
public :
template <class T> void isEqual(T x, T n)
{
Set(0);
if (x == n)
{
printf("is equal" );
cout << endl;
}
else
{
isBigger(T x, T n);
isSmaller(T x, T n);
}
}
template <class T> void isBigger(T x, T n)
{
if (x > n)
{
cout << x << " is bigger than " << n << endl;
}
}
template <class T> void isSmaller(T x, T n)
{
if (x < n)
{
cout << x << " is smaller than " << n << endl;
}
}
};
int main()
{
cout << "Worksheet 12 task 3" << endl;
Number<class T> num;
cout << "Please enter 2 integers" << endl;
cin >> intInput1;
cin >> intInput2;
Number<T>isEqual(T x, T n);
cout << "Please enter 2 floats" << endl;
cin >> floatInput1;
cin >> floatInput2;
Number<T>isEqual(T x, T n);
cin.ignore(2);
}
Mar 14, 2013 at 4:26pm UTC
The code shouldn't even compile.
Line 18 should be Number()
.
Line 37, 53 and 61. T is already used as a template argument for the class so you will have to call the template argument for the function something other than T.
Topic archived. No new replies allowed.