Jump to content
  • Advertisement
Sign in to follow this  
musasabi

STL vector iterator assignment based on index

This topic is 3795 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!