添加两个字符列表

在这个问题中,用户输入两个数字。每个数字代表一个整数,其字符存储在列表中。我需要修改+运算符,以便程序将获取两个列表字符,将它们更改为整数,添加它们,然后将其更改回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 + definition的代码。有任何想法吗?     
已邀请:
如果要将字符列表转换为int,可以执行以下操作:
std::list<char> digits;
int value = 0;
for(std::list<char>::iterator it = digits.begin(); 
    it != digits.end(); 
    ++it)
{
  value = value * 10 + *it - '0';
}
    
你可以启动这样的函数:
LongInt operator+(const LongInt& x, const LongInt& y) {
    // code goes here
}
此函数定义将超出类定义(可能在
.cpp
实现文件中)。 在此功能中,您可以使用正常的手写添加添加参数
x
y
(添加相应的数字对,处理任何进位等)。在本地
LongInt
对象中构建结果,并从
operator+()
函数返回计算值。 如果还没有为您决定,您需要确定最低有效数字是否在
val
列表中排在第一位或最后一位。这两种方式都是有效的,但是一种选择可能比另一种更容易(我会让你决定哪一种)。     

要回复问题请先登录注册