overloading +=

Hello, Please hele me for c++ programming. >"<

1. How I can overload operator+= member and non-member?

1
2
3
4
5
6
7
8
9
10
11
12
13
class Times{
private:
    int hour;
    int min;
    int sec;
public:
    Times(int, int, int);
    void print() const;
    void set(int, int, int);
    void incrementsec();
    void incrementmin();
    void incrementhour();
};



2. How I can overload operator+= member and non-member?
and How I can overload function lowterm?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Fraction{
private:
    int numerator;
    int denominator;
public:
    //Fraction(int);
    Fraction(int n = 1, int d = 1);
    void print() const;
    void setNumerator(int);
    void setDenominator(int);
    int getNumerator() const;
    int getDenominator() const;  
    Fraction add(const Fraction &) const;
    Fraction sub(const Fraction &) const;
    Fraction multiply(const Fraction &) const;
    Fraction divide(const Fraction &) const;
    void lowTerm();
};


Thank you very much
psuedocode
1
2
3
4
5
[type] & operator += ( const [type &] source)
{
   //work goes here
   return *this;
}
Last edited on
Thank you Nexius.

And I don't know that, operator+= have work function?
All non-primitive operators are functions! ┬┐How other did you think they are created?
Topic archived. No new replies allowed.