Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 15 January 2023 at 13:23:20 UTC, matheus wrote: On Sunday, 15 January 2023 at 12:44:51 UTC, thebluepandabear wrote: ... How will the variable `outer` become the reference to the current `X` object (if that makes sense?). Does the compiler do it automatically? I think you'll need

Re: D Static Array

2023-01-15 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 15 January 2023 at 14:23:59 UTC, Salih Dincer wrote:    int[0] arr = 40; // ? The = 40 means fill all array entries with the number 40. The [0] means there are no array elements. So it filled all the 0 elements with the number 40. If it was like int[3] arr = 40, then arr[0],

D Static Array

2023-01-15 Thread Salih Dincer via Digitalmars-d-learn
I wonder why the above code is allowed in D? Is there a special reason for this? ```d import std.stdio : writeln; void main() {    int[0] arr = 40; // ?        typeid(arr).writeln(": ", arr); // int[0]: [] } ``` When we look at the C side, the situation is deplorable! But I can claim that

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread matheus via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:44:51 UTC, thebluepandabear wrote: ... How will the variable `outer` become the reference to the current `X` object (if that makes sense?). Does the compiler do it automatically? I think you'll need to do this: class X { private int num; struct Y {

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread Hipreme via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:44:51 UTC, thebluepandabear wrote: Thanks. How will the variable `outer` become the reference to the current `X` object (if that makes sense?). Does the compiler do it automatically? You'll have to create your struct like `return Y(this)`. It basically

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:37:43 UTC, Paul Backus wrote: On Sunday, 15 January 2023 at 12:26:15 UTC, thebluepandabear wrote: If I have the following code: ```D class X { private int num; struct Y { // how to access num? } } ``` How would I access `num` from `Y`?

Re: How to access private variable of outer class from an inner struct

2023-01-15 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 15 January 2023 at 12:26:15 UTC, thebluepandabear wrote: If I have the following code: ```D class X { private int num; struct Y { // how to access num? } } ``` How would I access `num` from `Y`? Whenever I try to I get a compilation error. I believe that it's

How to access private variable of outer class from an inner struct

2023-01-15 Thread thebluepandabear via Digitalmars-d-learn
If I have the following code: ```D class X { private int num; struct Y { // how to access num? } } ``` How would I access `num` from `Y`? Whenever I try to I get a compilation error. I believe that it's possible for nested/inner classes, but I don't know if it's possible