K
karp
Lets say I have the following class in order to add two fractions,
class Fraction{
public:
Fractions::Fraction(int numer = 0, int denom = 1)
{
valeurNumerateur = numer;
valeurDenominateur = denom;
}
Rationnel Addition(const Fraction&) const;
private:
int num; //numerator
int den; //denominator
};
Fraction Fraction::Addition(const Fraction &Frac) const
{
Frac temp;
temp.den = den * Frac.den
temp.num = Frac.num * num +
den * Ration.num;
return temp;
}
Fraction operator+(const Fraction &Frac1, const Fraction &Frac1)
{
Fraction Result;
return Result.Addition(Frac1) + Result.Addition(Frac1)
}
int main()
{
Fraction a(2,3);
Fraction b(4,5);
Fraction c;
c = a + b;
cout << c;
return 0;
};
Input/output overloading works great (that is why it was not included in
this code) however when I try to overload addition with this structure all I
get is segmentation fault without any other errors. I need to use Fraction
operator+(const Fraction &Frac1, const Fraction &Frac1) as some sort of
interface to the actual Rationnel Addition(const Fraction&) const; which
does the work within my class. Parameters or structure may not be modified,
I was able to do it with a single overloading function but with this
structure it simply wont run....any help/tips would be much appreciated.
class Fraction{
public:
Fractions::Fraction(int numer = 0, int denom = 1)
{
valeurNumerateur = numer;
valeurDenominateur = denom;
}
Rationnel Addition(const Fraction&) const;
private:
int num; //numerator
int den; //denominator
};
Fraction Fraction::Addition(const Fraction &Frac) const
{
Frac temp;
temp.den = den * Frac.den
temp.num = Frac.num * num +
den * Ration.num;
return temp;
}
Fraction operator+(const Fraction &Frac1, const Fraction &Frac1)
{
Fraction Result;
return Result.Addition(Frac1) + Result.Addition(Frac1)
}
int main()
{
Fraction a(2,3);
Fraction b(4,5);
Fraction c;
c = a + b;
cout << c;
return 0;
};
Input/output overloading works great (that is why it was not included in
this code) however when I try to overload addition with this structure all I
get is segmentation fault without any other errors. I need to use Fraction
operator+(const Fraction &Frac1, const Fraction &Frac1) as some sort of
interface to the actual Rationnel Addition(const Fraction&) const; which
does the work within my class. Parameters or structure may not be modified,
I was able to do it with a single overloading function but with this
structure it simply wont run....any help/tips would be much appreciated.