Sign in to follow this  

STL vector iterator assignment based on index

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

id like to assign a std::vector::iterator based on user input that corresponds with the integer value of the index of another vector element. so...
class Blah
{
    ...
};

std::vector<Blah> blah;
int userInput = 0;
std::vector<Blah>::iterator itrBlah = blah.begin();

...

itrBlah = blah[userInput];
obviously that doesnt work. i get an error similar to
binary '=' : no operator found which takes a right-hand operand of type 'Blah' (or there is no acceptable conversion)
ive been googling and reading for a while, but i cant seem to sort out pointer math and apply it to this iterator situation. help please? ha. =)

Share this post


Link to post
Share on other sites
ah, thank you. thats working, of course, but now the accessor function i use to get the relative index value is causing an access violation and i have no idea why. i'll pick this up tomorrow.

Share this post


Link to post
Share on other sites

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