   need  help on template
  can somebody please convert my class into template?#include <iostream>using namespace std;class Fraction {public:    Fraction(int num = 0, int den = 1)    {   this->num = num;   this->den = den;    }    Fraction operator+(const Fraction &rhs)    {   Fraction temp;   temp.den = this->den * rhs.den;   temp.num = rhs.den * this->num +   this->den * rhs.num;   return temp;    }    Fraction operator-(const Fraction &rhs)    {   Fraction temp;   temp.den = this->den * rhs.den;   temp.num = rhs.den * this->num -   this->den * rhs.num;   return temp;    }    Fraction operator*(const Fraction &rhs)    {   Fraction temp;   temp.den = this->den * rhs.den;   temp.num = this->num * rhs.num;   return temp;    }    Fraction operator/(const Fraction &rhs)    {   Fraction temp;   temp.den = this->den * rhs.num;   temp.num = this->num * rhs.den;   return temp;    }    void print()    {   cout << num << "/" << den << endl << endl;    }private:    int num;    int den;};int main() {    Fraction a(1,2);    Fraction b(1,4);    Fraction c;    cout << "a is ";    a.print();    cout << "b is ";    b.print();    cout << "a + b = ";    c = a + b;    c.print();    cout << "a - b = ";    c = a - b;    c.print();    cout << "a * b = ";    c = a * b;    c.print();    cout << "a / b = ";    c = a / b;    c.print();    return 0;}  
quote:can somebody please convert my class To template?Please note that I only replaced all occurences of 'int' with 'T'. I added 'template <class T>' to tell the compiler that T is a template argument. #include <iostream>using std::cout;using std::endl;template <class T>    class Fraction {public:    Fraction(T num = 0, T den = 1)    {   this->num = num;   this->den = den;    }    Fraction operator+(const Fraction &rhs)    {   Fraction<T> temp;   temp.den = this->den * rhs.den;   temp.num = rhs.den * this->num +   this->den * rhs.num;   return temp;    }    Fraction operator-(const Fraction &rhs)    {   Fraction<T> temp;   temp.den = this->den * rhs.den;   temp.num = rhs.den * this->num -   this->den * rhs.num;   return temp;    }    Fraction operator*(const Fraction &rhs)    {   Fraction<T> temp;   temp.den = this->den * rhs.den;   temp.num = this->num * rhs.num;   return temp;    }    Fraction operator/(const Fraction &rhs)    {   Fraction<T> temp;   temp.den = this->den * rhs.num;   temp.num = this->num * rhs.den;   return temp;    }    void print()    {   cout << num << "/" << den << endl << endl;    }private:    T num;    T den;};int main() {    Fraction<int> a(1,2);    Fraction<int> b(1,4);    Fraction<int> c;    cout << "a is ";    a.print();    cout << "b is ";    b.print();    cout << "a + b = ";    c = a + b;    c.print();    cout << "a - b = ";    c = a - b;    c.print();    cout << "a * b = ";    c = a * b;    c.print();    cout << "a / b = ";    c = a / b;    c.print();    return 0;}  [edit]T main -> int main :-)[/edit]   [edited by - rule on February 19, 2004 6:42:57 AM]