   Vector Iterator problem in VS2005
  Hi I got some strange problem. I have code in visual c++ 6. and i upgrade it to VS 2005 compiler . Since this days STL changed lot of things i am getting some assert error. Here my code look like this.// look for v1vector<int>::iterator result = find(face.begin(),face.end(),v1);vector<int>::iterator prev = result - 1; // <=== this point i am getting assert error.Can anyone tell me why it gives me error ?[Edited by - nareshn2008 on May 29, 2009 5:04:39 AM]
  Maybe because std::find returns face.begin(). Then face.begin() - 1 is invalid.   ;  I don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)   ;Quote:Original post by CodekaI don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)Sorry i was miss it. I just want to show simple example :)   ;Quote:Original post by CodekaI don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)#include <vector>struct BSP_VertexInd {};namespace std {   template <> struct vector<BSP_VertexInd> { struct iterator {    template <typename T> iterator (T const &) {} };   };}using std::vector;vector<int>::iterator result;vector<BSP_VertexInd>::iterator prev = result - 1; // <=== this point i am getting assert error.int main () {}Compiles fine, no typedef harmed ;)   ;Quote:Original post by nareshn2008Quote:Original post by CodekaI don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)Sorry i was miss it. I just want to show simple example :)We will be able to help you if you post a real, preferably minimal, testcase :)   ;Quote:Original post by phresnelQuote:Original post by nareshn2008Quote:Original post by CodekaI don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)Sorry i was miss it. I just want to show simple example :)We will be able to help you if you post a real, preferably minimal, testcase :)Hi phresnel  Thanks for reply :)This is real code.vector<BSP_VertexInd>::iterator result = find(face.m_verts.begin(),face.m_verts.end(),v1);  vector<BSP_VertexInd>::iterator prev = result - 1; // << here is errorBSP_VertexInd is some sort of structure .;Quote:Original post by nareshn2008Quote:Original post by phresnelQuote:Original post by nareshn2008Quote:Original post by CodekaI don't see how that would compile, a vector<int>::iterator cannot be converted to a vector<BSP_VertexInd>::iterator (unless BSP_VertexInd is a typedef for int, but that would be confusing)Sorry i was miss it. I just want to show simple example :)We will be able to help you if you post a real, preferably minimal, testcase :)Hi phresnel  Thanks for reply :)This is real code.vector<BSP_VertexInd>::iterator result = find(face.m_verts.begin(),face.m_verts.end(),v1);  vector<BSP_VertexInd>::iterator prev = result - 1; // << here is errorBSP_VertexInd is some sort of structure .Did you check what std::find returns?   ;  HiIt is returns  face.begin(). So what will be trick to reverse_iterator ?   ;Quote:Original post by nareshn2008HiIt is returns  face.begin(). So what will be trick to reverse_iterator ?But what do you expect? You can't get an element before the first one. That's an error.   