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   |
Oblivion
Messages: 1206 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! ). 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
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 09 August 2017 13:48] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue May 13 23:17:29 CEST 2025
Total time taken to generate the page: 0.03355 seconds
|