Answered by:
the iterator of a list class

I want to define a nested class iterator of the dlist class, thus I coded it as following. I know it is incorrect but I do not know what is the right way...
//template <class T> class dNode; template <class T> class dlist{ private: int size; //other things public: class iterator;//nested class //other things } template <class T> //Problem 1：is this right， that is to say is the //iterator class a templated class? class dlist::iterator{ public: iterator(); func(); } template <class T>//Problem 2: how can I define the member function of the //iterator? dlist<T>::iterator<T>::iterator(){ //codes }
any help would be greatly appreciated~
Proust.Guan
Question
Answers

This link also can help "Templates, Nested classes,...":
 Marked as answer by 洛洛 Saturday, November 12, 2011 12:30 AM
All replies

�?�? <=?utf8?B?5rSb5rSb?=> wrote:
I want to define a nested class iterator of the dlist class, thus I coded it as following. I know it is incorrect but I do not
know what is the right way...[code]
//template <class T> class dNode;
template <class T>
class dlist{
private:
int size;
//other things
public:
class iterator;//nested class
//other things
}
template <class T> //Problem 1�?is this right�? that is to say is the
//iterator class a templated class?
class dlist::iterator{template <class T>
class dlist<T>::iterator {...};template <class T>//Problem 2: how can I define the member function of the
//iterator?
dlist<T>::iterator<T>::iterator(){
//codes
}template <class T>
dlist<T>::iterator::iterator() {...};
Igor Tandetnik

This link also can help "Templates, Nested classes,...":
 Marked as answer by 洛洛 Saturday, November 12, 2011 12:30 AM