Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Is pu****ng int...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9345 of 10094
Post > Topic >>

Is pu****ng into reserved space invalidating iterators?

by MathGis <mtahilferink@[EMAIL PROTECTED] > Mar 4, 2008 at 10:08 PM

Hi,

Is the following code legal?
I'm asking since the iterator debugging facility of VC++2005's stl
gives an assertion failed at runtime.

#include <vector>

int main(int argc, char** argv)
{
     std::vector<int> x;
     x.reserve(1);
     std::vector<int>::iterator i = x.end();
     x.push_back(1); // No reallocation
     if ( i != x.end()) // Debug Assertion failed: iterators
incompatible?
         return *i; // Debug Assertion failed: vector iterator not
dereferencable?
}

I had understood that iterators only become invalid when vector
operations cause reallocation.

Maarten Hilferink

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
Is pushing into reserved space invalidating iterators?
MathGis <mtahilferink@  2008-03-04 22:08:41 
Re: Is pushing into reserved space invalidating iterators?
Jeff Schwab <jeff@[EMA  2008-03-05 16:13:42 
Re: Is pushing into reserved space invalidating iterators?
peter koch larsen <pet  2008-03-05 16:13:47 
Re: Is pushing into reserved space invalidating iterators?
Mateusz Adamczyk <mate  2008-03-05 16:28:17 
Re: Is pushing into reserved space invalidating iterators?
Alberto Ganesh Barbati &l  2008-03-05 16:32:52 
Re: Is pushing into reserved space invalidating iterators?
Jiri Palecek <jpalecek  2008-03-05 16:31:34 
Re: Is pushing into reserved space invalidating iterators?
MathGis <mtahilferink@  2008-03-06 10:41:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 18:29:05 CDT 2008.