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

X

Xin Wang

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
 
S

Sumit Rajan

Xin Wang said:
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.
 
S

Sumit Rajan

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top