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

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

Post by Xin Wan » Tue, 05 Apr 2005 05:17:45



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
 
 
 

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

Post by Sumit Raja » Tue, 05 Apr 2005 05:28:19


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


Regards,
Sumit.
--
Sumit Rajan < XXXX@XXXXX.COM >

 
 
 

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

Post by Sumit Raja » Tue, 05 Apr 2005 05:39:37


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 < XXXX@XXXXX.COM >
 
 
 

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

Post by smilema » Wed, 06 Apr 2005 15:42:47

Did you delcare
using namespace std; ?

smilemac