【发布时间】:2010-11-09 03:35:49
【问题描述】:
我正在尝试将后缀增量运算符重载为将大数存储为整数数组的类的成员函数。但它一直返回为 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;
}
【问题讨论】:
-
您显示 LargeInt 但实际代码使用“数字”。 number 是对 LargeInt 的引用吗
-
operator++的参数不要命名;这是最佳实践
-
是的,我把它改成了largeInt,在我的程序中是正确的,只是有点累,从一个测试程序中复制粘贴。固定。
-
Chubsdad 表示名为“nothing”的参数。
标签: c++ arrays operator-overloading