#include<iostream>
#include<algorithm>
using namespace std;
template<class T>
class Array
{
public:
T& operator[](int);
Array(int);
~Array();
int get_size() const{return size;}
private:
T* a;
int size;
Araay();
T dummy_val;
};
template<class T>
T& Array<T>::operator [](int i)
{
if(i<0 || i>=size)
{
cout<<"error"<<endl;
return dummy_val;
}
return a[i];
}
template<class T>
Array<T>::Array(int s)
{
a=new T[size=s];
}
template<class T>
Array<T>:: ~Array()
{
delete a;
}
template<class T>
ostream& operator<<(ostream& out,Array<T>& a)
{
for(int i=0;i<a.get_size();i++)
out<<a[i]<<" ";
out<<endl;
return out;
}
template<class T>
istream& operator>>(istream& in,Array<T>& a)
{
for(int i=0;i<a.get_size();i++)
in>>a[i];
return in;
}
template<class T>
class ForwardIterator
{
public:
ForwardIterator(Array<T>&);
bool hasMoreElements();
int nextElement();
private:
Array<T>* t;
};
template<class T>
ForwardIterator<T>::ForwardIterator(Array<T>& f)
{
t=f;
}
template<class T>
bool ForwardIterator<T>::hasMoreElements()
{
}
template<class T>
int ForwardIterator<T>::nextElement()
{
}
void main()
{
Array<int>f(10);
cin>>f;
ForwardIterator<int>fi(f);
//while(fi.hasMoreElements())
//cout<<fi.nextElement();
}
这里的hasMoreElements()方法和nextElement();方法怎么写呢?请指教!!!
请教自己写一个跌代器