473,387 Members | 1,899 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,387 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 1810

"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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.