Problem about defining an iterator

Discussion in 'C++' started by yatko, Jan 22, 2008.

  1. yatko

    yatko Guest

    Hi all;

    I want to write a template class that uses STL list class and behaves
    as circular list. But when I try to define an iterator the compiler
    gives the following error. I really don't understand what I am doing
    wrong.

    Thanks

    yatko

    Error:

    Multiple markers at this line
    - type 'std::list<CircularList<DataType>::Node,
    std::allocator<CircularList<DataType>::Node> >' is not derived from
    type 'CircularList<DataType>'
    - expected ';' before 'popIterator'



    template < class DataType>
    class CircularList
    {

    public:
    ...

    private:

    struct Node
    {
    DataType *dataptr;
    bool valid;
    };


    list< Node > linear;

    list < Node >::iterator popIterator;

    ..

    };
    yatko, Jan 22, 2008
    #1
    1. Advertising

  2. yatko wrote:
    > Hi all;
    >
    > I want to write a template class that uses STL list class and behaves
    > as circular list. But when I try to define an iterator the compiler
    > gives the following error. I really don't understand what I am doing
    > wrong.


    Read up on dependent names.

    > [..]
    > list < Node >::iterator popIterator;


    typename list<Node>::iterator popIterator;

    >
    > ..
    >
    > };


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 22, 2008
    #2
    1. Advertising

  3. yatko

    yatko Guest

    Thanks very much V.

    >
    > Read up on dependent names.
    >
    yatko, Jan 22, 2008
    #3
  4. yatko

    yatko Guest

    One more thing, it seems that both list<Node> and list<Node>::iterator
    are dependent-names. But why there is no any error, when I dont use
    typename for the declaration of list<Node> linear.

    Thanks

    yatko
    yatko, Jan 22, 2008
    #4
  5. yatko

    Guest

    On Jan 22, 2:26 pm, yatko <> wrote:
    > One more thing, it seems that both list<Node> and list<Node>::iterator
    > are dependent-names. But why there is no any error, when I dont use
    > typename for the declaration of list<Node> linear.


    list<Node> is the name of a type. That type is the result type of the
    instantiation of the list class template.

    list<T>::iterator depends on what T is: depending on whether list is
    specialized for that type T, iterator may be a member object, an enum
    value, a type, etc.

    Ali
    , Jan 22, 2008
    #5
  6. yatko

    James Kanze Guest

    On Jan 22, 11:26 pm, yatko <> wrote:
    > One more thing, it seems that both list<Node> and
    > list<Node>::iterator are dependent-names. But why there is no
    > any error, when I dont use typename for the declaration of
    > list<Node> linear.


    Because the compiler knows that list<Node> is a type. The name
    "list", by itself, is not dependent, and the compiler find the
    class template at the definition point of the template, and
    binds the name to it. And since it is a class template, all
    specializations must be a class type.

    What the compiler doesn't know is what might be in any
    particular specialization. It can't know whether
    list<Node>::iterator names a member type, or a member variable,
    or a member function, or whatever. And for various
    histerical^H^H^H^H^H^Horical reasons, it's impossible to
    effectively parse C++ without knowing whether a symbol names a a
    type or something else.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jan 23, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,404
  2. johny smith
    Replies:
    8
    Views:
    401
    Peter Koch Larsen
    Jul 2, 2004
  3. michaelmei
    Replies:
    2
    Views:
    687
    michaelmei
    Oct 9, 2006
  4. Urs Thuermann
    Replies:
    6
    Views:
    450
    Urs Thuermann
    Nov 4, 2011
  5. Jim Anderson

    problem with iterator (map iterator)

    Jim Anderson, Jan 10, 2014, in forum: C++
    Replies:
    3
    Views:
    108
    Luca Risolia
    Jan 13, 2014
Loading...

Share This Page