Jump to content
  • Advertisement
Sign in to follow this  
harmless

Newbie question about STL templates

This topic is 3817 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

Hello folks, Recently i have been studying STL templates and i have a few questions that i hope someone could answer: 1. if list is empty, what will be the value of iterator returned from calling list.begin()? is it null? it seems so from my observation. If it is, then can i assume that iterators basically a pointer to the element that holds the data stored in the list? 2. say i want to access the data stored in the list specified by an iterator, is *iterator the only way? Thanks a lot!

Share this post


Link to post
Share on other sites
Advertisement
1) It's a std::list::iterator that is equal to the result of end(). This can be anything. You cannot assume it's a pointer or really anything else.

2) You can also use the -> operator on iterators to access members of the contained object.

Share this post


Link to post
Share on other sites
1. value of .end() - it doesn't matter what it is, it's the value of invalid iterator. Dereferencing it is invalid and undefined. Iterators are also not pointers, so they can't be NULL.
2. depending on type stored in container, you can sometimes use ->

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!