I don´t know how to reassign the value of two -in main- created class objects in order to reuse them inside an operator overload.
My operation overload should sum two numbers treating the nominator and denominator separately.
//This is my Declaration:
public:
Fraction operator+ (Fraction& obj);
//...
private:
int nenner;
int zaehler;
//This is what I tried in the Implementation:
Fraction::operator+(Fraction& obj, Fraction& obj2)
{
Fraction res;
int nenner1 = obj.getNenner();
int nenner2 = obj2.getNenner();
int zaehler1 = obj.getZaehler();
int zaehler2 = obj2.getZaehler();
int newNenner = Fraction::kgV(nenner1, nenner2);
int newZaehler = zaehler1 * (newNenner / nenner1)+ zaehler1*(newNenner / nenner2);
res = Fraction(newZaehler, newNenner);
return res;
}
Aucun commentaire:
Enregistrer un commentaire