Solved (Crash due to pilot error) Re: Serious Issue With std::vector
Solved (Crash due to pilot error) Re: Serious Issue With std::vector
- Subject: Solved (Crash due to pilot error) Re: Serious Issue With std::vector
- From: Adin Hunter Baber <email@hidden>
- Date: Sun, 4 Dec 2005 17:49:59 -0600
On 2005 Dec 04, at 5:21 PM, Sandy Martel wrote:
Here's a simpler version of the problem:
std::vector<std::vector<std::string> > v;
v.push_back( std::vector< std::string >() );
std::vector< std::string > &ref = v[0];
v.push_back( std::vector< std::string >() );
ref.push_back( "test" );
Can you spot the bug? I extract a reference from a vector, then I
modify the vector, possibly invalidating all references I had to
object inside it and then I try to use ref !
Look at your code, it does the same thing.
Sandy.
I discovered that after I posted :-/
And thus I am reminded about the rule in the standard that says: all
iterators, pointers, and references are invalid if the vector changes
size.
Moral of the story, use indexes if you are changing the vector.
Adin Hunter Baber
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden