我对类非常陌生,虽然我编写了所有其他代码,但在我的两个成员函数的末尾我仍然缺乏一些实现。
这是我的标题:
class bignum
{
public:
// Constructors.
bignum();
bignum(int num_digits);
bignum(const string &digits);
bignum(const bignum &other);
// Destructors.
~bignum();
// Assignment operator.
bignum &operator=(const bignum &other);
// Accessors
int digits() const;
int as_int() const;
string as_string() const;
void print(ostream &out) const;
bignum add(const bignum &other) const;
bignum multiply(const bignum &other) const;
bool equals(const bignum &other) const;
int PublicNumberTest;
private:
// Pointer to a dynamically-allocated array of integers.
int *digit;
// Number of digits in the array, not counting leading zeros.
int ndigits;
};
#endif
这是我的成员函数之一:
bignum bignum::multiply(const bignum& other) const{
bignum product;
bignum row;
int carry = 0;
int sum = 0;
int j = 0;
int *temp_row = new int[];
for (int i = 0; i < ndigits-1; i++){
carry = 0;
temp_row[i] = 0;
for (j; j < other.digits - 1; j++){
sum = digit[i] * other.digit[j] + carry;
temp_row[i + j] = sum % 10;
carry = sum / 10;
}
if (carry>0)
temp_row[i + j] = carry;
row = row operator+temp_row //This is what I don't understand. How can I
product = product.add(row); //assign the contents of temp_row?
}
}
还有一个,但基本上是同样的问题。我有一个数组,我想将其复制到我的...类的内容并放置在其中?我猜?谢谢阅读。