我對類很陌生,雖然我編寫了所有其他代碼,但在我的兩個成員函數結束時,我停滯不前。我在哪裏使用賦值運算符?
這裏是我的頭:
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?
}
}
還有另一種,但它基本上是同樣的問題。我有一個數組,我想複製到我的...課程的內容和地方?我猜?謝謝閱讀。
你想執行c = a * b還是a = a * b?也就是說,你是否打算將兩個參數相乘,產生一個臨時的,並將其分配給第三個參數,或者你是否打算將參數b乘以對象a? – ChuckCottrill
我的意圖是C = A * B – OddLogic