Iterator and STL question

I have something like the following code:

std::advance(this->mSprites.begin(), std::distance(other.mSprites.begin(), other.mCurrentDisplay));

Where this and other are the same type, mSprites is a vector, and mCurrentDisplay is an iterator from the above vector.

This code currently gives me an error:
error C2782: 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)' : template parameter '_InIt' is ambiguous


Why? Both mSprites are the same type of vector, so their iterators and difference types should be the same, right?
Last edited on
The std::advance() iterator function takes a reference.
http://www.cplusplus.com/reference/std/iterator/advance/

See if that fixes your problem. (If it doesn't, please post back.)
Oh whoops. Anyway, it didn't fix the problem...

std::advance(this->mCurrentDisplay, std::distance(other.mSprites.begin(), other.mCurrentDisplay));

Still gives me the error.
The use of the std::distance function is at fault here.
Your two parameter types are mismatched - other.mSprites.begin(), other.mCurrentDisplay
That was my next thought also. Chances are that one is const and the other is not...
Hm, other is actually not a const object.

As for the parameter mismatch, other.mCurrentDisplay is from mSprites too, so wouldn't it be the same type as mSprites.begin()?
Ok, there were 4 of these errors total, and I fixed the top two (other was a const reference), and after fixing those, the other 2 disappeared. Odd.
Topic archived. No new replies allowed.