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 » Array problems
Re: Array problems [message #48619 is a reply to message #48618] Wed, 09 August 2017 13:34 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello,

Answer to question 2 (your first question is closely related to your second question): You are deallocating an already deallocated memory (testLayout). Because you've passed the address of a stack allocated object to Array (which is nor forbidden since Array does not know, nor does it care how, or from where (stack or heap), its elements are created as long as you give its address. It allows taking the ownership (of HEAP allocated objects). Read the docs Luke! Smile ). But you forget that when the array gets destroyed, so is testlayout. So you are also corrupting the program's heap, since testLAyout is allocated from stack, and "&layout" gets "delete[ed]" which is a valid operation only on heap-allocated objects.

Did you try:
Array<WithTestLayout<ParentCtrl> > layouts;
auto& testLayout = layouts.Add(); // <-- Creates the ParentCtrl with the given layout as its element.


Best regards,
Oblivion


[Updated on: Wed, 09 August 2017 13:48]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is there a U++ function to copy a String contents to the clipboard
Next Topic: Missing ArrayIndex and AIndex
Goto Forum:
  


Current Time: Mon Jun 17 01:05:20 CEST 2024

Total time taken to generate the page: 0.06148 seconds