none
the iterator of a list class

    Question

  • 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
    Friday, November 11, 2011 7:17 AM

Answers

All replies

  • �?�? <=?utf-8?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

    Friday, November 11, 2011 1:08 PM
    • Marked as answer by 洛洛 Saturday, November 12, 2011 12:30 AM
    Friday, November 11, 2011 1:36 PM