472,789 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Iterator Issue

KL
Well, I got through those other hurdles, but now I am stuck with trying
to get an iterator to work.

I am having a problem with trying to iterate through the STL list
container that I set up. I have the #include<list> and the using
std::list; and then a using std::list<int>::iterator; but I get an error
that says, "p3a.cpp:12: error: `std::list<int, std::allocator<int> >' is
not a namespace"

So it stops working on any iterators before I can even get to them.
Then it says they are undeclared. If I comment out the code having to
do with iterators and this one std::list<int>::iterator; part of the
code my program works so far. But I really need that iterator to see
that my list is filling up properly. Any suggestions?

I didn't want to post all the code, it is a class assignment and I would
be embarrased by the simplicity of it compared to you who are experts.
If the code is needed to help with this problem, I will be glad to post it.

--
KL
Mar 5 '06 #1
4 1777

"KL" <kl*******@aohell.com> schrieb im Newsbeitrag
news:0K********************@telcove.net...
Well, I got through those other hurdles, but now I am stuck with trying to
get an iterator to work.

I am having a problem with trying to iterate through the STL list
container that I set up. I have the #include<list> and the using
std::list; and then a using std::list<int>::iterator; but I get an error
that says, "p3a.cpp:12: error: `std::list<int, std::allocator<int> >' is
not a namespace"


As the error say... list<int> is not a namespace...

so you can only do: using std::list;
and declare the iterator with: list<int>::iterator myIterator;
or if that is to long, you can use a typedef: typedef list<int>::iterator
intListIterator;
Mar 5 '06 #2
"KL" <kl*******@aohell.com> wrote in message
news:0K********************@telcove.net...
Well, I got through those other hurdles, but now I am stuck with trying to
get an iterator to work.

I am having a problem with trying to iterate through the STL list
container that I set up. I have the #include<list> and the using
std::list; and then a using std::list<int>::iterator; but I get an error
that says, "p3a.cpp:12: error: `std::list<int, std::allocator<int> >' is
not a namespace"

So it stops working on any iterators before I can even get to them. Then
it says they are undeclared. If I comment out the code having to do with
iterators and this one std::list<int>::iterator; part of the code my
program works so far. But I really need that iterator to see that my list
is filling up properly. Any suggestions?

I didn't want to post all the code, it is a class assignment and I would
be embarrased by the simplicity of it compared to you who are experts. If
the code is needed to help with this problem, I will be glad to post it.

--
KL


Code snippets from my own code doing a reverse iteratorion on a list of
std::string. Not complete compilable code. Just showing syntax mostly.

#include <list>

std::list< std::string > ChatMessages;

ChatMessages.push_back( "Client Initiated..." );

for ( std::list<std::string>::reverse_iterator ri = ChatMessages.rbegin();
ri != ChatMessages.rend(); ++ri)
{
jDraw_Text(&Client.Font, 5, y, const_cast<char*>((*ri).c_str()),
jColor(255,255,255,255), Client.EmptyTexture);
...
};

change the reverse_iterator to iterator. change rbegin() to begin().
change rend() to end(). Eventhing else should stay the same.

Are yo udoing somethign like this?

( The const_cast<char*> is just because this jDraw_Text is expecting a non
const char * as a parm and I've confirmed that the function does not change
the c-style string array. I wish the developer would change the call
though )
Mar 5 '06 #3
KL wrote:
I am having a problem with trying to iterate through the STL list
container that I set up. I have the #include<list> and the using
std::list; and then a using std::list<int>::iterator; but I get an error
that says, "p3a.cpp:12: error: `std::list<int, std::allocator<int> >' is
not a namespace"


At namespace level you can use a using declaration only for namespace
level entities. However, 'std::list<int>::iterator' is actually
referring to a member of the class template 'std::list'. Thus, you
cannot use it with a using declaration. However, you can use it with
a typedef if you need to give it a short name:

#include <list>
using std::list;
typedef std::list<int>::iterator iterator;

Note, that within a template, you might end up with a dependent
name requiring an additional 'typename' keyword. However, disregard
this statement if you are not using templates...
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 5 '06 #4
KL
on 3/5/2006 12:03 AM Dietmar Kuehl said the following:
KL wrote:
I am having a problem with trying to iterate through the STL list
container that I set up. I have the #include<list> and the using
std::list; and then a using std::list<int>::iterator; but I get an error
that says, "p3a.cpp:12: error: `std::list<int, std::allocator<int> >' is
not a namespace"

At namespace level you can use a using declaration only for namespace
level entities. However, 'std::list<int>::iterator' is actually
referring to a member of the class template 'std::list'. Thus, you
cannot use it with a using declaration. However, you can use it with
a typedef if you need to give it a short name:

#include <list>
using std::list;
typedef std::list<int>::iterator iterator;

Note, that within a template, you might end up with a dependent
name requiring an additional 'typename' keyword. However, disregard
this statement if you are not using templates...


Thank you all for all your help. Got this submitted and now for some
well-deserved rest.

--
KL
Mar 5 '06 #5

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

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
9
by: Alexander Stippler | last post by:
Hi, I've got trouble with some well known issue. Iterator invalidation. My situation: for (it=v.begin(); it!=v.end(); ++it) { f(*it); } Under some circumstances, f may alter the container...
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...
2
by: Dave | last post by:
I'm crossposting this to both comp.lang.c++ and gnu.gcc because I'm not sure if this is correct behavior or not, and I'm using the gcc STL and compiler. When calling vector<int>::push_back(0),...
3
by: uclamathguy | last post by:
I am working on connected component analysis, but that is irrelevant. I have a mapping containing ints as the keys and sets of ints as the "values." Given an integer, I need to iterate through...
12
by: Mark P | last post by:
Is it guaranteed that STL iterators are aggregate types and can thus be derived from? I'm thinking along the lines of, for example: class DerIter : public std::vector<int>::iterator {...}; ...
14
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
3
by: vasili | last post by:
hello All, I have a simple issue. I defined a custom container, that encloses a std::list, which in turn holds objects that are a simple abstraction of a six position array. Now, i would like...
1
jlm699
by: jlm699 | last post by:
Greetings friends. I'm trying to create an iterator to iterate over a database of messages. I defined an __iter__() and a next() function as such: import win32com.client as w32c from...
5
by: maverik | last post by:
Hi all. I'm implementing class AbstractCollection - just a wrap on std::vector - to hide from clients the fact of using std::vector in the base (because in the future I may change vector to a...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.