473,320 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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


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

Jul 23 '05 #1
2 1228

"Xin Wang" <wa****@yahoo.com> wrote in message
news:Pi*******************************@flop.ENGR.O RST.EDU...

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 <su*********@gmail.com>
Jul 23 '05 #2

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:3b*************@individual.net...
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 <su*********@gmail.com>
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
3
by: John Smith | last post by:
Hey I have some code which I've been using on Microsoft VC++ for some time. Now I wanted to port my application to Mac OS X which offers gcc and the build fails. Here is the troublesome code:...
1
by: James Aguilar | last post by:
Hey all, I ran into an interesting little problem with defining an iterator in a custom array class the other day. It goes something like this: template <typename T> class Array { public:...
3
by: Ken Cecka | last post by:
This is a contrived example to demonstrate a syntax problem I'm struggling with: #include <vector> template <typename T> class Class { };
13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
3
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general...
1
by: flopbucket | last post by:
Hi, For the learning experience, I am building a replacement for std::map. I built a templated red-black tree, etc., and all the basic stuff is working well. I implemented basic iterators and...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
7
by: Ralf Goertz | last post by:
Hi, the following templated code doesn't compile. It gives the error: template_it.cc:17: error: type 'std::vector<Derived1<T>*, std::allocator<Derived1<T>*' is not derived from type...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.