Reputation: 4658
I have a vector like this
std::vector<Sprite*> mDrawings;
std::vector<Sprite*>::iterator it = mDrawings.begin();
This gives an error
Error: no suitable user-defined conversion from std::_Vector_iterator<std::_Vector_val<Sprite *, std::allocator<Sprite *>>> to std::_Vector_iterator<std::_Vector_val<Sprite *, std::allocator<Sprite *>>> exists
But if i do the following
typedef std::vector<Sprite*> list;
list mDrawings;
list::iterator it = mDrawings.begin();
Then it works ???.
UPDATE: Im sorry it seems like the error was generated because of errors not related to the current code. I just saw the IDE underline with red and i thought that was the reason my application would not compile.
Upvotes: 1
Views: 1687
Reputation: 91300
I think you pasted the wrong code - I think perhaps you did std::vector<Sprite>::iterator it = mDrawings.begin();
without the *
EDIT: In response to updated question:
Always look at the first compiler error - Your code, as posted on ideone, lacks an #include
which makes Sprite
visible.
Upvotes: 2
Reputation: 94429
Your pasted code doesn't actually show the error. However, here's another shot in the dark:
Is it possible that in your original case, mDrawings
is a member variable of some class (just guessign from the m
prefix) and that your real code is in a const method? If so, you'd be trying to assing a const_iterator
(since that's what calling begin()
on a const vector will yield) to an iterator
, which isn't possible.
Try using
std::vector<Sprite *>::const_iterator it = mDrawings.begin();
does that work better?
Upvotes: 3