Sign in to follow this  
Sync Views

vectore problems again

Recommended Posts

Sync Views    139
Why does this not work when the 2nd one does?
	for (std::vector<object*>::iterator it = object_list_depth.end(); it != object_list_depth.begin(); it--)
		if((*it)!=NULL && (*it)->active) (*it)->draw();//Vector iterator is not dereferencable

		for (std::vector<object*>::iterator it = object_list_depth.begin(); it != object_list_depth.end(); it++)
			if((*it)!=NULL && (*it)->active) (*it)->draw();

Share this post


Link to post
Share on other sites
RIZAX    127
stl vector's end method returns 1 pass the end of the list, so the first deference isn't actually returning anything in the list, try using:


for (std::vector<object*>::iterator it = object_list_depth.end()-1; it != object_list_depth.begin(); it--)
if((*it)!=NULL && (*it)->active) (*it)->draw();//

Share this post


Link to post
Share on other sites
Sync Views    139

...vc\include\vector
Line: 163

Expression:("_Myptr + _Off <= ((_Myvec *)(this->_Getmycount()))->_Mylast&&_Myptr+_off >=((_Myvec *)(this->Getmycount()))->_Myfirst",0)


for (std::vector<object*>::iterator it = object_list_depth.end()-1; it != object_list_depth.begin(); it--)//HERE
if((*it)!=NULL && (*it)->active) (*it)->draw();

Share this post


Link to post
Share on other sites
ToohrVyk    1596
Don't.

The operation v.end() - 1 will obviously fail on an empty vector. Instead of making life hard for yourself using normal iterators, use std::vector::rbegin and std::vector::rend.

Share this post


Link to post
Share on other sites
RIZAX    127
you could also try using a reverse_iterator ... so:(check that syntax though I don't have an IDE in front of me)

for (std::vector<object*>::reverse_iterator it = object_list_depth.begin(); it != object_list_depth.end(); it++)
if((*it)!=NULL && (*it)->active) (*it)->draw();

Share this post


Link to post
Share on other sites
MaR_dev    154
for (std::vector<object*>::reverse_iterator it = object_list_depth.rbegin(); it != object_list_depth.rend(); it++)
if((*it)!=NULL && (*it)->active) (*it)->draw();

EDIT: note just fixed RIZAXs example, he forgot to add those 'r's.

[Edited by - MaR_dev on February 22, 2008 6:28:40 AM]

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