【发布时间】:2011-04-06 03:11:32
【问题描述】:
在这个问题中,用户输入了两个数字。每个数字代表一个整数,其字符存储在一个列表中。我需要修改 + 运算符,以便程序将获取两个列表字符,将它们更改为 int,添加它们,然后将其更改回 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+ 定义的代码。有什么想法吗?
【问题讨论】:
-
如果这是家庭作业,那么你应该这样标记它。
标签: c++ list operators overriding definition