Thread: Overloading probs

  1. #1
    reyal
    Guest

    Overloading probs

    Anyone know how to overload a += operator in a rational problem?

    Ex:

    rational r1 = 5/6
    rationa r2 = 3/5

    r1+=r2

    r1 will have a new value 43/30.

    any help will be much appreciated.

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    I'm not familiar with rationals, but you have to think about how they are added normally and then apply that to the overloaded operator. += is usually declared as a member function so the code might look something like this:

    Code:
    rational& rational::operator +=( rational& rvalue )
    {
          //addition code
         return *this;
    }
    If you explain rationals for me (I cant be arsed to search at the moment), I'lll probably be able to help more.
    Last edited by endo; 09-03-2002 at 06:29 AM.
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading operators
    By ugmusicbiz in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2009, 01:41 PM
  2. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  3. Replies: 16
    Last Post: 10-27-2007, 12:42 PM
  4. overloading for newbies
    By lime in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 02:58 PM
  5. passing discards qualifiers? overloading =...
    By Captain Penguin in forum C++ Programming
    Replies: 9
    Last Post: 10-07-2002, 05:38 PM