Is iterator definition with template not a type in ISO C++?

Discussion in 'C++' started by Xin Wang, Apr 3, 2005.

  1. Xin Wang

    Xin Wang Guest

    Hi,

    I tried to declare an iterator inside a template class, but the compiler
    regards list<State>::iterator as an expression, instead of an iterator.

    #include <list>

    template <class State>
    class Problem
    {
    ..
    ..
    ..
    list<State>::iterator itr;
    ..
    ..
    ..
    }

    What's wrong here, what should I do to fix this problem?

    Thanks a lot!


    Xin Wang
    Xin Wang, Apr 3, 2005
    #1
    1. Advertising

  2. Xin Wang

    Sumit Rajan Guest

    "Xin Wang" <> wrote in message
    news:p...
    >
    > Hi,
    >
    > I tried to declare an iterator inside a template class, but the compiler
    > regards list<State>::iterator as an expression, instead of an iterator.
    >
    > #include <list>
    >
    > template <class State>
    > class Problem
    > {
    > .
    > .
    > .
    > list<State>::iterator itr;


    This changes to:
    typename std::list<State>::iterator itr;


    Regards,
    Sumit.
    --
    Sumit Rajan <>
    Sumit Rajan, Apr 3, 2005
    #2
    1. Advertising

  3. Xin Wang

    Sumit Rajan Guest

    "Sumit Rajan" <> wrote in message
    news:...

    > This changes to:
    > typename std::list<State>::iterator itr;


    I should have explained why the word "typename" comes into the picture. It
    is used to clarify that "iterator" is a type (and not a static member of
    list).

    Regards,
    Sumit.
    --
    Sumit Rajan <>
    Sumit Rajan, Apr 3, 2005
    #3
    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. Franck DARRAS
    Replies:
    12
    Views:
    633
    Jim Higson
    Aug 23, 2004
  2. Alexei Polkhanov
    Replies:
    11
    Views:
    2,458
  3. Replies:
    13
    Views:
    6,416
    Dave Thompson
    Dec 20, 2004
  4. ISO C89 and ISO C99

    , Dec 10, 2004, in forum: C Programming
    Replies:
    18
    Views:
    544
    Dave Thompson
    Dec 20, 2004
  5. Pierre Yves
    Replies:
    2
    Views:
    481
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page