Reputation: 199
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;
}
Upvotes: 1
Views: 1781
Reputation: 40346
Your comment disagrees with your code. operator++(int)
is postfix increment, operator++()
is prefix.
Upvotes: 3