• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Solved (Crash due to pilot error) Re: Serious Issue With std::vector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Serious Issue With std::vector (From: Adin Hunter Baber <email@hidden>)
 >Re: Serious Issue With std::vector (From: Sandy Martel <email@hidden>)

  • Prev by Date: Re: Serious Issue With std::vector
  • Next by Date: Debugger can not find source file
  • Previous by thread: Re: Serious Issue With std::vector
  • Next by thread: Debugger can not find source file
  • Index(es):
    • Date
    • Thread