Scope exit bug?
void foo() { void bar() { foo; } switch case: scope(exit) { do } break bar; } fails to execute do void foo() { void bar() { foo; } switch case: bar; do return; bar; } does work... yet there is no difference except the scope exit. In my code it is if do is never executed... I used it to avoid having to write bar twice or use a flag but it's not working... I see no reason why it should not work. scope(exit) is suppose to execute the block at the end of the function call, right?
Re: Proper desctructor for an class containing dynamic array of objects
On Thursday, 13 June 2019 at 16:08:52 UTC, Mike wrote: How would a proper destructor of class Foo look like? Is it enough to set "array" to null? Or do I have to set every element of the array to null and then the array, or nothing of that at all because the garbage collecter collects it, if the reference to Foo is set to null? Nothing at all, GC will take care. As long as your Block class doesn't create any system resources that must be discarded.
Re: Proper desctructor for an class containing dynamic array of objects
On Thursday, 13 June 2019 at 16:08:52 UTC, Mike wrote: or nothing of that at all because the garbage collecter collects it, if the reference to Foo is set to null? That. [The init loop can be shortened to `foreach (ref b; array) b = new Block();`.]
Proper desctructor for an class containing dynamic array of objects
Hi, my name is Mike and I'm new to D (coming from a Javabackground) and for fun I'm trying to learn D now. I created a simple class class Block { int a, b; this() {} } And now I have a dynamic array of objects of this class in another class: class Foo { Block[] array = new Block[](10); this() { for (int i = 0; i < array.length; i++) { array[i] = new Block(); } } } How would a proper destructor of class Foo look like? Is it enough to set "array" to null? Or do I have to set every element of the array to null and then the array, or nothing of that at all because the garbage collecter collects it, if the reference to Foo is set to null?
Re: How to "Inherit" the attributes from a given callable argument?
On Thursday, June 13, 2019 3:49:04 AM MDT Jacob Carlborg via Digitalmars-d- learn wrote: > On 2019-06-12 22:42, Mek101 wrote: > > I didn't know it applied to templates other than lambdas. > > > > Thank you for your explanation. > > It applies to templates, lambdas (which basically are templates) and > nested functions. It also now applies to auto return functions, though that's a more recent change. - Jonathan M Davis
Re: How to "Inherit" the attributes from a given callable argument?
On 2019-06-12 22:42, Mek101 wrote: I didn't know it applied to templates other than lambdas. Thank you for your explanation. It applies to templates, lambdas (which basically are templates) and nested functions. -- /Jacob Carlborg