I have two classes Polynom
and Fraction
.
I need to do a template for Polynom
, for using Fraction
like coefficient in Polynom
, like: 3/4 x^0 + 5\6 x^1
etc.
I understood how to use a simple type like double
or int
, but how to get this to work for a class I have no idea, and can't find a material on this theme.
class Fraction {
private:
int numerator, denominator;
public:
Fraction();
Fraction(int, int);
Fraction(int);
}
template<class T>
class PolynomT {
private:
int degree;
T *coef;
public:
PolynomT();
explicit PolynomT(int, const T * = nullptr);
~PolynomT();
};
template<class T>
PolynomT<T>::PolynomT(int n, const T *data): degree(n) {
coefA = new T[degree+1];
if (data == nullptr) {
for (int i = 0; i < degree+1; ++i)
coefA[i] = 0.0;
}
else {
for (int i = 0; i < degree + 1; ++i)
coefA[i] = data[i];
}
}
/*Problem here*/
int main() {
PolynomT<Fraction> a(); // what need to pass on here in arguments?
// how should the constructor look like?
/*Example*/
PolynomT<Fraction> b();
PolynomT<Fraction> c = a + b; // or something like this.
}
So, how to do the class constructor for Fraction
in PolynomT
, and how to do overloading operators for this?