Jump to content
  • Advertisement
Sign in to follow this  
nareshn2008

Vector Iterator problem in VS2005

This topic is 3369 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

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 v1 vector<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]

Share this post


Link to post
Share on other sites
Advertisement
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)

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
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)


Sorry i was miss it. I just want to show simple example :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
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)


#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 ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by nareshn2008
Quote:
Original post by Codeka
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)


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 :)

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Quote:
Original post by nareshn2008
Quote:
Original post by Codeka
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)


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 error

BSP_VertexInd is some sort of structure .


Share this post


Link to post
Share on other sites
Quote:
Original post by nareshn2008
Quote:
Original post by phresnel
Quote:
Original post by nareshn2008
Quote:
Original post by Codeka
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)


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 error

BSP_VertexInd is some sort of structure .


Did you check what std::find returns?

Share this post


Link to post
Share on other sites
Quote:
Original post by nareshn2008
Hi

It 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.

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!