Sign in to follow this  
musasabi

STL vector iterator assignment based on index

Recommended Posts

musasabi    133
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
musasabi    133
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

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