それは私の一般的な配列ヘッダーファイルです:
#ifndef ARRAY_H
#define ARRAY_H
#include "Number.h"
#include "Iterator.h"
//array is contius memory of numbers
class Array{
protected:
//array has some contius cell of memory each include the data
class Cell{
public:
Number* m_data;
//c'tor:(inline)
Cell(Number* num=NULL): m_data(num){};
//D'tor (inline)
~Cell(){};
};
//composition class of iterator:
class ArrayIterator:public Iterator{
public:
Cell* m_current;
//C'tor:(inline)
ArrayIterator(Cell* cell):m_current(cell){};
//D'tor:
~ArrayIterator(){};
//is there any next numbers
bool hasNext()const;
//is there any prev numbers
bool hasPrev()const;
//returning the current and getforward
Number& next();
//returning the current and getback
Number& prev();
};
Cell* m_head,*m_last;
public:
//C'tor:
Array(const int amount);
//D'tor:
virtual ~Array(){delete[]m_head;};
//Random access operator:
Number& operator [] (const int i)const{return *m_head[i].m_data;};
};
#endif
Number と Iterator を抽象クラスと見なし、Number は一般的な数値を表します。
私の質問: ArrayIterator は構成クラスであり、配列のサイズを「認識」していないため、ArrayIterator に hasNext() を実装する方法