Adding two fractions

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.
 
M

Mike Wahler

karp said:
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.

"Won't run" tells us nothing.

Post the real code that fails.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top