简体   繁体   中英

Overloading postfix increment operator

I am trying to overload the postfix increment operator as a member function for a class which stores large numbers as an array of ints. But it keeps getting returned as 0. Any tips on why this doesn't work?

This is a homework question, so I would like more of a tip than straight code. Thanks.

The member data looks like:

largeInt = new int[maxSize];
int maxSize, currentSize;

Where currentSize is a tracking variable used to keep track of how big the array currently is.

And my code is:

The Load function puts an int at the first spot in the array and shifts everything else over.

/* postfix*/
NewInt& NewInt::operator++(int nothing)
{   
    int count = 1;
    largeInt[currentSize - count] += 1;
    while(largeInt[currentSize - count] > 9)
    {
            if(currentSize - count - 1 < 0)
            {
                    firstVar = true;
                    Load(1);
            }
            else    
                    largeInt[currentSize - count - 1] += 1;

            count++;              
    }

    return *this;
}   

Your comment disagrees with your code. operator++(int) is postfix increment, operator++() is prefix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM