我有一个关于这个承包商实际上在做什么的问题。我在网上找到了它,它适用于我的目的,但我希望了解它的符号。
class Iterator {
int i;
public:
Iterator(int i = 0) : i(i) {};
friend class SinglyLinkedList<Element>;
Node* _current;
Iterator(SinglyLinkedList& list) {
this->list = list;
reset();
}
void reset() {
_current = list._head;
}
void next(){
if(!done()) {
_current = _current->_next;
}
}
bool done(){
bool done = false;
if(_current->_next == nullptr) {
done = true;
}
return done;
}
private:
SinglyLinkedList list;
};
这是一个证明它有效的成员函数。
unsigned long print(Element e, const Iterator& index) {
cout << index.i << "\n";
return 0;
当const Iterator& index = 2
. 函数输出 2。
如果你忽略关于 的部分Element e
,基本的想法是我可以使用Iterator(SinglyLinkedList& list)
and Iterator(int i = 0)
,两者都可以。您可以使用 ? 访问整数属性index.i
?
任何一般的见解也值得赞赏。