【发布时间】:2019-09-16 20:52:01
【问题描述】:
我正在尝试重载 operator+,我想使用迭代器添加两个节点,但我在从另一个对象访问迭代器时遇到问题。
这是我的运算符+:
type operator+(const largeInt<type> &other) {
iter = list.end();
other.iter = other.list.end() //need help here
type newNumb1, newNumb2;
newNumb1 = *iter;
newNumb2 = other.*iter; //need help here
return newNumb1 + newNumb2;
}
我有这个 typename List<type>::Iterator iter; 作为 largeInt 类中的私有数据成员。
迭代器类保存在另一个类中,它嵌套在一个链表类中,这就是为什么要创建一个迭代器对象我必须做List<type>::Iterator 虽然它工作我无法使用另一个传递为的 largeInt 对象来访问它参考。
更新:
type operator+(const largeInt<type> &other) {
typename List<type>::Iterator other_iter = other.iter;
type newNumb1, newNumb2;
newNumb1 = *iter;
newNumb2 = *other_iter;
return newNumb1 + newNumb2;
}
这行得通,但我想做同样的事情,但不必制作额外的迭代器,任何帮助都会很棒。
【问题讨论】:
-
*other.iter怎么样?
标签: c++ c++11 data-structures linked-list operator-overloading