在这个问题中,用户输入两个数字。每个数字代表一个整数,其字符存储在一个列表中。我需要修改+运算符,以便程序将采用两个列表字符,将它们更改为整数,添加它们,然后将其更改回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