468,256 Members | 1,451 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

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 1601

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

38 posts views Thread by Grant Edwards | last post: by
9 posts views Thread by Alexander Stippler | last post: by
26 posts views Thread by Michael Klatt | last post: by
3 posts views Thread by uclamathguy | last post: by
12 posts views Thread by Mark P | last post: by
3 posts views Thread by vasili | last post: by
jlm699
1 post views Thread by jlm699 | last post: by
5 posts views Thread by maverik | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.