首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >超载预增量算子

超载预增量算子
EN

Stack Overflow用户
提问于 2020-05-03 18:15:47
回答 1查看 80关注 0票数 2

以下是宣言:

代码语言:javascript
复制
 Iterator operator++();//pre-increment

以下是定义:

代码语言:javascript
复制
LinkedList::Iterator& LinkedList::Iterator::operator++(){
   return Iterator(current->next);//this is giving me an error
}

这是这门课的样子

代码语言:javascript
复制
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
    }
} 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-03 19:16:58

创建一个新的迭代器对象,并(尝试)返回对此的引用。

前缀增量运算符修改this对象,并应返回对自身的引用:

代码语言:javascript
复制
current = current->next;  // TODO: Add checking for not going out of bounds or dereferencing a null pointer
return *this;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61579440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档