View Single Post
  #8 (permalink)  
Old February 7th, 2006, 05:20 PM
mikhailberis mikhailberis is offline
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mikhailberis
Default

Quote:
quote:Originally posted by Jonax
 Thanks Vector - the following seems to work:
Code:
...
    friend cBigApple operator -- (cBigApple tmp) 
    {
        return cBigApple(--tmp.iWormCount, --tmp.fTotalLengthOfWorms, 0.0);
    }
};
...
You might want to make the argument to operator-- a reference to the original object, and return a reference to the object itself. It might look like:

Code:
...
const cBigApple & operator -- (cBigApple & tmp) {
    iWormCount -= 1;
    fTotalLenthOfWorms -= 1;
    return *this;
}
...
This will make sure that the returned object is not a new instance, but rather the same instance with which you called the operator-- with.

This should apply to the other unary operators too.

Hope this helps.

Dean Michael C. Berris
Orange and Bronze Technologies, Inc.
Mobile +639287291459
Reply With Quote