Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Wrong(?) ASSERT in Vector<>::Insert()
Re: Wrong(?) ASSERT in Vector<>::Insert() [message #27997 is a reply to message #27807] Fri, 13 August 2010 09:34 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
dolik.rce wrote on Wed, 04 August 2010 17:33

Hello,
I just hit a problem in Vector code and I feel a need for explanation Smile . Have a look at this code
#include <Core/Core.h>
using namespace Upp;

CONSOLE_APP_MAIN{
	Vector<int> v;
	v.Add(123);
	v.Insert(0,v[0]);
}




It is classical and nasty bug.

Insert expects a reference, but at the same time invalidates references to v.

Not that in this particular case, we could workaround it in Vector code, but there are other similar cases where this is not quite possible:

http://www.ultimatepp.org/srcdoc$Core$Caveats$en-us.html

so I decided to forbid them all.

(And thanks kohait, you are 100% right).

And yes, I am not happy about this, but I guess ASSERT is best we can get here....
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: better Stream manual....more info needed
Next Topic: NEW: BufferStream
Goto Forum:
  


Current Time: Wed Jun 05 04:36:00 CEST 2024

Total time taken to generate the page: 0.01636 seconds