Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Muppi

Can someone please explain this?

This topic is 5378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was reading the Enguinity article, but i got stuck at one part.
for(std::list::iterator it=deadObjects.begin();
       it!=deadObjects.end(); it++)
 
this part i need explained
std::list::iterator it=deadObjects.begin();
 
Thanks!

Share this post


Link to post
Share on other sites
Advertisement
deadObjects.begin() is probably a pointer to the first object in a list of objects

Share this post


Link to post
Share on other sites
STL iterators are just like pointers which are used to iterate through STL containers much like you can use a pointer to iterate through an array

Share this post


Link to post
Share on other sites
Others have pretty much answered your question, or at least pointed you to where you need to look... STL List containers.

In the code fragment, DeadObjects is a

list ANGLE_BRACKET some_objects ANGLE_BRACKET

container, where some_objects is the type of objects defined to be kept in the list. List containers contain two methods being used here: list.begin(), which returns a list::iterator (a pointer, basically) to the first item in the list, and
list.end() which returns an iterator to one beyond the end of the list. That is so that you can construct loops like those shown that iterate through each item in the list.

edit: trying to make angle brackets show up
(Sorry about the ANGLE_BRACKETS...)
[edited by - algol on March 24, 2004 9:36:38 AM]

[edited by - algol on March 24, 2004 9:38:26 AM]

[edited by - algol on March 24, 2004 9:40:06 AM]

Share this post


Link to post
Share on other sites
In C# it would be

foreach(jobclass job in deadObjects)
{
job.dosomething();
}


A std::list is comparable to an arraylist in C#, except that because of C++ you have to do some things yourself, like get begin and end, while C# supports lists with foreach()

Share this post


Link to post
Share on other sites
quote:
Original post by Fidelio66
In C# it would be

foreach(jobclass job in deadObjects)
{
job.dosomething();
}

The STL provides std::foreach in the <algorithm> header. (Just FYI.) Of course, it''s even easier in Python:
for obj in deadObjects:
obj.dosomething()


Best of all, it''s trivial to create your own iterators (simply provide next() in the iterator, and __iter__() in the sequence to be iterated).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!