itemiterator.h

来自「《Big C++ 》Third Edition电子书和代码全集-Part1」· C头文件 代码 · 共 43 行

H
43
字号
#ifndef ITEMITERATOR_H
#define ITEMITERATOR_H

#include <vector>
#include "item.h"

/**
   An iterator through a collection of items
*/
class ItemIterator
{
public:
   /**
      Constructs the iterator from a vector.
      @param its a reference to a vector of Item pointers
   */
   ItemIterator(vector<Item*>& its);
   /**
      Gets the current item.
      @return the current item pointer
   */
   Item* get() const;
   /**
      Advances to the next item.
   */
   void next();
   /**
      Tests whether there are more items.
      @return true if no more items are available.
   */
   bool is_done() const;
private:
   const vector<Item*>& items;
   int pos;
};

inline void ItemIterator::next()
{
   pos++;
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?