Names and scope in D
Dibyendu Majumdar
d.majumdar at gmail.com
Sat Nov 14 17:37:48 UTC 2020
On Saturday, 14 November 2020 at 17:22:13 UTC, Paul Backus wrote:
> On Saturday, 14 November 2020 at 17:06:49 UTC, Dibyendu
> Majumdar wrote:
>> I couldn't find the rules that D uses to decide whether a name
>> conflicts or not. If I missed something please can someone
>> point me to it?
>
> It doesn't appear to be spelled out anywhere in the language
> spec, but the rule is that two symbols in the same scope with
> the same name conflict unless they form an overload set. The
> rules for overload sets are laid out in the sections of the
> spec that deal with functions, templates, and aliases (iirc).
Thank you.
If I do this, compiler accepts it:
//int foo;
struct foo {
int a;
}
void bar() {
foo foo;
foo.a = 5;
}
So if I read your reply correctly the variable 'foo' in bar()
doesn't conflict with the struct 'foo' because it is in a
different scope?
More information about the Digitalmars-d
mailing list