Sign in to follow this  

Newbie question about STL templates

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

This topic is 3626 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this