以下是宣言:
Iterator operator++();//pre-increment以下是定义:
LinkedList::Iterator& LinkedList::Iterator::operator++(){
return Iterator(current->next);//this is giving me an error
}这是这门课的样子
class LinkedList{
public:
Node struct{
/*contains pointer to next node and an integer value*/
int val;
Node* next;
};
class Iterator{
public:
Iterator& operator++();//pre-increment
protected:
Node* current;//points to current node
}
} 发布于 2020-05-03 19:16:58
创建一个新的迭代器对象,并(尝试)返回对此的引用。
前缀增量运算符修改this对象,并应返回对自身的引用:
current = current->next; // TODO: Add checking for not going out of bounds or dereferencing a null pointer
return *this;https://stackoverflow.com/questions/61579440
复制相似问题