Foo Foo = new Foo();

JN 666total at wp.pl
Sun Feb 21 18:15:22 UTC 2021


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 global; 
> you can override identifiers from global in main. And "Foo" 
> only exists after the declaration, so it doesn't conflict.

I was worried I hit some corner case where it compiles even 
though it shouldn't. Can lead to some confusing code. I guess D 
is smart enough to figure out which is a type and which is a 
variable. C++ gets confused in similar situation.


More information about the Digitalmars-d-learn mailing list