在這個問題中,用戶輸入兩個數字。每個數字代表一個整數,其字符存儲在一個列表中。我需要修改+運算符,以便程序將採用兩個列表字符,將它們更改爲整數,添加它們,然後將其更改回char列表。令人困惑的是我知道,但希望代碼能夠幫助你清除問題:添加兩個字符列表
class LongInt
{
public:
friend LongInt operator+(const LongInt& x, const LongInt& y); //This function will add the value of the two integers which are represented by x and y's character list (val).
private:
list<char> val; //the list of characters that represent the integer the user inputted
}
這是LongInt類的頭文件。還有其他部分,如構造函數,析構函數等,但在這種情況下,這些是唯一重要的事情。我不知道如何去編寫實現文件中operator +定義的代碼。有任何想法嗎?
如果是這樣的功課,那麼你應該將其標記爲此類。 – Jollymorphic 2011-04-06 03:15:00