Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 21:03:27 UTC, Jack wrote: Why doesn't this compiles? class Baa { Foo Foo = new Foo(); } Local variables inside functions are a little bit special because everything happens in sequence. This is a declaration, where there is a new namespace, but order

Re: Foo Foo = new Foo();

2021-02-21 Thread Jack via Digitalmars-d-learn
Why doesn't this compiles? class Baa { Foo Foo = new Foo(); }

Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:15:22 UTC, JN wrote: I guess D is smart enough to figure out which is a type and which is a variable. C++ gets confused in similar situation. Well it isn't about type vs variable (except for in this exact declaration), it is just one is defined at top level

Re: Foo Foo = new Foo();

2021-02-21 Thread JN via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:09:29 UTC, FeepingCreature wrote: On Sunday, 21 February 2021 at 18:07:49 UTC, JN wrote: class Foo { } void main() { Foo Foo = new Foo(); } this kind of code compiles. Is this expected to compile? Yes, why wouldn't it? main is a different scope than

Re: Foo Foo = new Foo();

2021-02-21 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:07:49 UTC, JN wrote: class Foo { } void main() { Foo Foo = new Foo(); } this kind of code compiles. Is this expected to compile? Yes, why wouldn't it? main is a different scope than global; you can override identifiers from global in main. And "Foo"