重载后缀增量运算符
我试图将后缀增量运算符重载为将大量数字存储为整数数组的类的成员函数。但它总是返回 0。关于为什么这不起作用的任何提示?
这是一个家庭作业问题,所以我想要更多的提示而不是直接的代码。谢谢。
成员数据如下所示:
largeInt = new int[maxSize];
int maxSize, currentSize;
其中 currentSize 是一个跟踪变量,用于跟踪数组当前有多大。
我的代码是:
Load 函数将一个 int 放在数组的第一个位置,并将其他所有内容移过来。
/* 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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的评论与您的代码不一致。
operator++(int)
是后缀增量,operator++()
是前缀。Your comment disagrees with your code.
operator++(int)
is postfix increment,operator++()
is prefix.