Container of iterators (newbie)

Discussion in 'C++' started by Carter, Jan 25, 2009.

  1. Carter

    Carter Guest

    Hi,

    I am trying to construct a container of iterators using STL and I seem
    to be getting an error which I have been having difficulties figuring
    out. The code is as follows:

    std::list< std::list<K>::iterator > _scopes;

    Which gives the following error:

    type/value mismatch at argument 1 in template parameter list for
    ‘template<class _Tp, class _Alloc> class std::list’
    environment.cpp:46: error: expected a type, got
    ‘std::list::iterator’
    environment.cpp:46: error: template argument 2 is invalid

    If anyone can shed light on this I would appreciate it.

    Thanks in advance,
    Carter, Jan 25, 2009
    #1
    1. Advertising

  2. Carter

    Kai-Uwe Bux Guest

    Carter wrote:

    > Hi,
    >
    > I am trying to construct a container of iterators using STL and I seem
    > to be getting an error which I have been having difficulties figuring
    > out. The code is as follows:
    >
    > std::list< std::list<K>::iterator > _scopes;
    >
    > Which gives the following error:
    >
    > type/value mismatch at argument 1 in template parameter list for
    > ?template<class _Tp, class _Alloc> class std::list?
    > environment.cpp:46: error: expected a type, got
    > ?std::list::iterator?
    > environment.cpp:46: error: template argument 2 is invalid


    Presumably, the above line is part of a template and K is a typename
    parameter to that template. Then, you should try:

    std::list< typename std::list<K>::iterator > _scopes;


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 25, 2009
    #2
    1. Advertising

  3. Carter

    Carter Guest

    On Jan 26, 3:31 am, Kai-Uwe Bux <> wrote:
    > Carter wrote:
    > > Hi,

    >
    > > I am trying to construct a container of iterators using STL and I seem
    > > to be getting an error which I have been having difficulties figuring
    > > out. The code is as follows:

    >
    > > std::list< std::list<K>::iterator > _scopes;

    >
    > > Which gives the following error:

    >
    > > type/value mismatch at argument 1 in template parameter list for
    > > ?template<class _Tp, class _Alloc> class std::list?
    > > environment.cpp:46: error:   expected a type, got
    > > ?std::list::iterator?
    > > environment.cpp:46: error: template argument 2 is invalid

    >
    > Presumably, the above line is part of a template and K is a typename
    > parameter to that template. Then, you should try:
    >
    >   std::list< typename std::list<K>::iterator > _scopes;
    >
    > Best
    >
    > Kai-Uwe Bux


    Thanks that fixed the problem. I am however curious as to when in
    general the addition of typename is required to disambiguate things
    for the compiler. What exactly and when should you add the additional
    typename keyword to a declaration?

    Thanks,

    Carter
    Carter, Jan 29, 2009
    #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. moggous phar
    Replies:
    1
    Views:
    379
    Gianni Mariani
    Oct 15, 2004
  2. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    484
    Kai-Uwe Bux
    May 8, 2005
  3. Patrick Kowalzick

    Iterators over nested STL container

    Patrick Kowalzick, Aug 3, 2005, in forum: C++
    Replies:
    2
    Views:
    380
    Chris Theis
    Aug 3, 2005
  4. Replies:
    1
    Views:
    375
    Michael DOUBEZ
    Feb 6, 2008
  5. , India
    Replies:
    10
    Views:
    1,072
    James Kanze
    Aug 8, 2009
Loading...

Share This Page